Converts a string into a URL-friendly slug. Handles accents and special characters.

Syntax

TypeScript
import { slugify } from "@opentf/std";
slugify(str: string): string;

Parameters

NameTypeDescription
strstringThe string to slugify.

Returns

A lowercase, hyphen-separated slug containing only a–z, 0–9 and -.

Examples

TypeScript
slugify('Hello World!'); //=> 'hello-world'

slugify('Café au Lait'); //=> 'cafe-au-lait'

slugify('Special characters like @#$%'); //=> 'special-characters-like'
Info

Diacritics are transliterated rather than stripped, so a letter with no Unicode decomposition becomes its ASCII equivalent instead of being dropped from the slug.

TypeScript
slugify('Straße'); //=> 'strasse'
slugify('Ølberg'); //=> 'olberg'
slugify('Łódź');   //=> 'lodz'
slugify('Þór');    //=> 'thor'
Last updated on
Edit this page