Skip to content

Function: slugify()

slugify(value): string

Defined in: string.ts:54

Converts a string into a URL-friendly slug.

  • Accented characters are converted to their base ASCII equivalents
  • Emojis and other non-ASCII characters are removed
  • Whitespace characters are replaced with -
  • Other non-alphanumeric characters are replaced with _
  • Consecutive separators are collapsed into one
  • Leading and trailing separators are removed

Parameters

value

string

The string to slugify.

Returns

string

The slugified string.

Example

ts
slugify('Hello World')     // 'hello-world'
slugify('Héllo Wörld')     // 'hello-world'
slugify('foo-bar')         // 'foo-bar'
slugify('foo@bar')         // 'foo_bar'
slugify('foo @ bar')       // 'foo-bar'
slugify('hello!')          // 'hello'