28 lines
733 B
TypeScript
28 lines
733 B
TypeScript
import crypto from "crypto";
|
|
import { clsx, type ClassValue } from "clsx";
|
|
import { twMerge } from "tailwind-merge";
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs));
|
|
}
|
|
|
|
export function randomToken(length = 48): string {
|
|
let token = "";
|
|
|
|
while (token.length < length) {
|
|
token += crypto
|
|
.randomBytes(Math.max(16, Math.ceil(length * 0.8)))
|
|
.toString("base64url")
|
|
.replace(/[^a-zA-Z0-9]/g, "");
|
|
}
|
|
|
|
return token.slice(0, length);
|
|
}
|
|
|
|
export function renderLegalTokens(template: string, companyName: string) {
|
|
const year = String(new Date().getFullYear());
|
|
return template
|
|
.replace(/\{\{\s*year\s*\}\}/gi, year)
|
|
.replace(/\{\{\s*companyName\s*\}\}/gi, companyName);
|
|
}
|