31 lines
660 B
TypeScript
31 lines
660 B
TypeScript
export const normalizePhone = (phone: string): string => {
|
|
phone = phone.replace(/\D/g, '');
|
|
|
|
if (phone.startsWith('9')) {
|
|
return '0' + phone;
|
|
}
|
|
|
|
return phone;
|
|
};
|
|
|
|
type GenerateCodeOptions = {
|
|
prefix?: string;
|
|
length?: number;
|
|
};
|
|
|
|
export const generateCode = (options?: GenerateCodeOptions) => {
|
|
const prefix = options?.prefix || '';
|
|
const length = options?.length || 5;
|
|
|
|
const characters =
|
|
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
let random = '';
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
random += characters.charAt(Math.floor(Math.random() * characters.length));
|
|
}
|
|
|
|
return `${prefix}${random}`;
|
|
};
|