Skip to content

Tlouverse/slugify

Repository files navigation

@tlouverse/slugs

Dependency-free slugification utilities for frontend and Node.js apps.

Links

Install

npm install @tlouverse/slugs

Usage

import { slugify, slugifyLines } from '@tlouverse/slugs';

slugify("John's cafe & bakery");
// "johns-cafe-and-bakery"

slugify('cafe 中文 Привет', { preserveUnicode: true });
// "cafe-中文-привет"

slugify('café 中文 Привет', { transliterate: false, preserveUnicode: true });
// "café-中文-привет"

slugifyLines('First title\nSecond title');
// ["first-title", "second-title"]

slugifyLines(['First title', 'Second title']);
// ["first-title", "second-title"]

API

slugify(input, options?)

Returns a single slug string.

Options:

Option Default Description
separator '-' Separator inserted between slug parts. Supports '-', '_', and '.'.
lowercase true Lowercase the result.
transliterate true Fold accents and common Latin characters to ASCII, such as é -> e, ß -> ss, and ø -> o.
preserveUnicode false Preserve Unicode letters and numbers instead of forcing ASCII-only output.
wordSubstitutions true Replace common symbols like &, @, +, %, and # with words.
maxLength 0 Maximum slug length. 0 means unlimited.

slugifyLines(input, options?)

Accepts either a text block or an array of strings. Text blocks are split on \n, \r\n, or \r; arrays are treated as already-split logical lines.

Additional option:

Option Default Description
preserveEmptyLines false Keep empty slug lines instead of filtering them out.

Defaults

The default output is ASCII-first for broad compatibility with URLs, logs, APIs, filesystems, and older systems. Use preserveUnicode: true when readable native-language slugs are preferred.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors