-
-
Notifications
You must be signed in to change notification settings - Fork 70
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Clear and concise description of the problem
Would be amazing if the package includes a slugify util to convert a string to an URL-slug, it's pretty commonly used when building ECOM / content-centric web applications.
Suggested solution
Probably something like:
export function slugify(text: string): string {
return text
.toLowerCase()
.normalize('NFD') // split accented chars
.replace(/[\u0300-\u036F]/g, '') // remove accents
.replace(/[^a-z0-9]+/g, '-') // replace non-alphanumerics with -
.replace(/^-+|-+$/g, '') // trim leading/trailing -
}I've been using the above snippet for a few projects, haven't hit any weird cases yet.
Alternative
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guide.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request