Skip to content

API Reference


API Reference / @dasch-ng/web-utils / toSlug

Function: toSlug() ​

toSlug(value, options?): string

Defined in: slug.ts:68

Turns text into a URL slug of [a-z0-9-]: lowercased, accents removed, German umlauts written out, everything else collapsed into single dashes, cut at a word boundary. NFC and NFD spellings of the same text give the same slug.

Parameters ​

value ​

string | null | undefined

options? ​

SlugOptions = {}

Returns ​

string

Example ​

typescript
toSlug('Grüne Wälder über Köln');                 // 'gruene-waelder-ueber-koeln'
toSlug('Café au Łódź');                           // 'cafe-au-lodz'
toSlug('Grün', { expandUmlauts: false });         // 'grun'
toSlug('東京', { fallback: 'item-42' });           // 'item-42'

Released under the MIT License.