CyrefJS
CCyrefJS
فا
Back to documentation
String/Since 1.38.0

slugify

Converts a string into a normalized, lowercase, URL-friendly slug.

slugify(value):string

Normalization

The input is first normalized using Unicode NFKC normalization. This can normalize compatible Unicode representations before the slug is generated.

Lowercase conversion

After normalization and trimming, the entire string is converted to lowercase.

Character replacement

Every consecutive sequence of characters that is not a Unicode letter or number is replaced with a single hyphen. Unicode property escapes are used, so letters and numbers from supported Unicode scripts are preserved.

Final cleanup

Any hyphens at the beginning or end of the generated slug are removed.

Parameters

valuestringrequired

The string to convert into a slug.

Returns

string

A lowercase slug with runs of non-letter and non-number characters replaced by a single hyphen.

Examples

01

Basic usage

Convert a regular phrase into a URL-friendly slug.

TypeScript
slugify("Hello World");
// "hello-world"
02

Multiple separators

Consecutive spaces and punctuation are collapsed into a single hyphen.

TypeScript
slugify("Hello,   World!!!");
// "hello-world"
03

Leading and trailing separators

Leading and trailing hyphens are removed from the result.

TypeScript
slugify("---Hello World---");
// "hello-world"
04

Unicode text

Unicode letters and numbers are preserved.

TypeScript
slugify("سلام دنیا");
// "سلام-دنیا"
05

Trimming whitespace

Leading and trailing whitespace is removed before slug generation.

TypeScript
slugify("  Hello World  ");
// "hello-world"
06

Empty result

A string containing only characters outside the supported letter and number categories produces an empty string.

TypeScript
slugify("!!! @@@ ###");
// ""
Built with@cyref/js·Official documentation