Skip to content

Instantly share code, notes, and snippets.

@docentedev
Created December 15, 2022 19:34
Show Gist options
  • Save docentedev/5084419044d2c8490b23db9a38cb7d54 to your computer and use it in GitHub Desktop.
Save docentedev/5084419044d2c8490b23db9a38cb7d54 to your computer and use it in GitHub Desktop.
index.utils.ts
export const textNormalize = (str: string) => {
const value = str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
if (value === undefined) return '';
return value
.trim()
.replace(/[^a-z0-9_]+/gi, '-')
.replace(/^-|-$/g, '')
.toLowerCase();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment