Created
December 15, 2022 19:34
-
-
Save docentedev/5084419044d2c8490b23db9a38cb7d54 to your computer and use it in GitHub Desktop.
index.utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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