mirror of
https://github.com/uetchy/namae.git
synced 2025-08-20 18:08:11 +09:00
feat: location based domain suggestion
This commit is contained in:
@@ -5,11 +5,43 @@ export function capitalize(text: string): string {
|
||||
|
||||
export function sanitize(text: string): string {
|
||||
return text
|
||||
.replace(/[\s@+!#$%^&*()[\]./<>{}]/g, '')
|
||||
.replace(/[@+!#$%^&*()[\]./<>{}]/g, '')
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '');
|
||||
}
|
||||
|
||||
export interface NormalizeOptions {
|
||||
alphanumeric?: boolean;
|
||||
allowSpaces?: boolean;
|
||||
allowUnderscore?: boolean;
|
||||
allowHyphens?: boolean;
|
||||
}
|
||||
|
||||
export function normalize(
|
||||
text: string,
|
||||
{
|
||||
alphanumeric = true,
|
||||
allowSpaces = false,
|
||||
allowUnderscore = true,
|
||||
allowHyphens = true,
|
||||
}: NormalizeOptions = {}
|
||||
): string {
|
||||
if (alphanumeric) {
|
||||
text = text.replace(/[^0-9a-zA-Z-_\s]/g, '');
|
||||
}
|
||||
if (!allowUnderscore) {
|
||||
text = text.replace(/_/g, '-');
|
||||
}
|
||||
if (!allowHyphens) {
|
||||
text = text.replace(/-/g, allowUnderscore ? '_' : ' ');
|
||||
}
|
||||
if (!allowSpaces) {
|
||||
text = text.replace(/\s/g, '');
|
||||
}
|
||||
text = text.replace(/[-_\s]+$/, '');
|
||||
return text;
|
||||
}
|
||||
|
||||
export function upper(word: string): string {
|
||||
return word.toUpperCase();
|
||||
}
|
||||
|
Reference in New Issue
Block a user