mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-14 08:53:11 +00:00
11 lines
464 B
TypeScript
11 lines
464 B
TypeScript
/** A slug as this module produces it: lowercase alphanumerics, hyphen-separated. */
|
|
export const SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
|
|
|
|
export const slugify = (value: string): string =>
|
|
value
|
|
.normalize('NFD')
|
|
.replace(/[\u0300-\u036f]/g, '') // strip accents
|
|
.toLowerCase()
|
|
.replace(/[^a-z0-9]+/g, '-') // non-alphanumeric -> hyphen
|
|
.replace(/-+/g, '-') // collapse hyphens
|
|
.replace(/^-|-$/g, '') // trim leading/trailing hyphens
|