1
0
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:
2021-02-25 15:13:15 +09:00
parent 7fbc430949
commit 73de4dd7ca
31 changed files with 1674 additions and 1499 deletions

View File

@@ -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();
}