slugify

Slugify a string with accurate Unicode transliteration for URLs, filenames, and IDs.

Library
npm
v3.0.1
2,704stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
61/100Good
Development Activity60
Maintenance36
Community48
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
75/100Good
Architecture78
Code Quality90
Innovation68
Learning Curve65

@sindresorhus/slugify turns any string into a lowercase, URL- and filename-safe slug. It transliterates non-Latin scripts — German umlauts, Vietnamese, Arabic, Russian, and more — into ASCII equivalents, decamelizes identifiers while correctly preserving acronyms and plural forms, and strips the apostrophe from contractions and possessives so Conway's Law becomes conways-law rather than conway-s-law.

Beyond the default export, the package includes slugifyWithCounter(), a stateful helper that appends numeric suffixes to repeated slugs — useful for generating collision-free heading anchors across a single document. The library is intentionally small and dependency-light, ships as ESM-only for Node 20+, and exposes granular options for separator characters, casing, custom replacements, locale-specific transliteration, and character preservation.

What You Get

  • A default slugify(string, options?) export with sensible defaults (lowercase, decamelize, and transliterate all enabled)
  • A slugifyWithCounter() factory that tracks previously seen slugs and appends numeric suffixes to duplicates
  • Built-in transliteration for German, Vietnamese, Arabic, Russian, and other major scripts via @sindresorhus/transliterate
  • Options for separator character, casing, custom replacements, locale, and character preservation
  • Full TypeScript type definitions (index.d.ts) with documented options and inline usage examples

Common Use Cases

  • Generating SEO-friendly URL slugs from post or page titles
  • Producing unique anchor IDs for markdown or HTML headings
  • Sanitizing user-uploaded filenames before writing them to disk or object storage
  • Normalizing multilingual text into a consistent ASCII key for search indexes and deduplication

Under The Hood

Architecture The package is a single-file, purely functional ESM module (index.js) with no classes or internal state beyond the closure inside slugifyWithCounter(). The default slugify export runs a fixed pipeline — custom-replacement substitution via @sindresorhus/transliterate, decamelize, a dynamically built buildPatternSlug regex driven by the active options, contraction stripping, and finally removeMootSeparators — with small dedicated helpers for each stage rather than one monolithic function. slugifyWithCounter() wraps the same pipeline in a Map-backed closure that tracks prior slugs and appends a numeric suffix on repeats. Because every stage is a pure function taking explicit options, the abstraction that would break first is buildPatternSlug, since every option (preserveCharacters, transliterate, casing) folds into the single negation-set regex it builds.

Tech Stack The project is ESM-only ("type": "module"), targets Node.js 20+, and ships hand-written TypeScript declarations (index.d.ts) alongside plain JavaScript source rather than compiling from TypeScript. Runtime dependencies are minimal and both from the same author’s ecosystem: @sindresorhus/transliterate for Unicode-to-ASCII conversion and escape-string-regexp for safely embedding a user-supplied separator into dynamically constructed regexes. Testing runs on ava, linting on xo (the author’s opinionated ESLint preset), and there is no separate build step — the files field ships index.js, index.d.ts, and overridable-replacements.js directly.

Code Quality The test suite is extensive relative to the module’s size, covering basic slugification, camelCase/acronym decamelization (including plural-acronym edge cases like APIs vs APISection), contraction and possessive handling across straight and curly apostrophes, emoji and symbol replacement, and locale-specific transliteration. Errors are handled explicitly — a non-string argument throws a TypeError with a descriptive message rather than failing silently. Source comments call out specific regex-performance decisions (avoiding quadratic backtracking on repeated-character runs), indicating deliberate attention to correctness under adversarial input. CI runs the test suite via GitHub Actions across a Node.js version matrix (20 and 24) on every push and pull request.

What Makes It Unique Most slugify implementations treat decamelization and transliteration as simple find-and-replace passes; this one instead builds its character-matching regex dynamically per call based on the active options and handles compound edge cases explicitly — plural acronyms staying intact through camelCase splitting, contractions dropping only their word-final apostrophe without disturbing unrelated ones, and a counter-aware variant purpose-built for generating collision-free anchors. The engineering is a careful refinement of a well-understood problem rather than a novel algorithmic approach, but the attention to edge-case correctness and regex-performance safety distinguishes it from more naive slugify libraries in the same ecosystem.

Used by 19 apps in this directory

TypeScript
89%
Other

anytype-ts

Knowledge Management · Note Taking · Collaboration

8,755

A local-first, end-to-end encrypted knowledge OS that lets you build notes, tasks, wikis, and entire apps — with your data stored offline and synced peer-to-peer.

View details
88
Repo Health
78
Technical
67
Dependency
Built with
TypeScript89%
Updated 2 days ago
Ruby
49%
Other

Chatwoot

Customer Support

36,549

Open-source omnichannel customer support platform with AI-powered agents, live chat, and self-hosting — a full Intercom and Zendesk alternative.

View details
95
Repo Health
78
Technical
69
Dependency
Built with
Ruby49%
Vue26%
JavaScript22%
Updated yesterday
TypeScript
93%
AGPL 3.0

CourseLit

Ecommerce · Blogging

1,262

Open-source, self-hosted LMS for selling online courses, digital downloads, and building communities on your own branded website.

View details
75
Repo Health
74
Technical
71
Dependency
Built with
TypeScript93%
Updated 1 months ago
TypeScript
81%
Other

Directus

CMS · Low Code Platforms

37,783

Connect any SQL database and get instant REST and GraphQL APIs, a visual management Studio, and a native MCP server for AI agents — free for most organizations.

View details
92
Repo Health
82
Technical
76
Dependency
Built with
TypeScript81%
Vue18%
Updated 3 days ago
TypeScript
95%
AGPL 3.0

Docmost

Productivity · Note Taking · Collaboration

21,600

Self-hosted collaborative wiki and knowledge base with real-time editing, diagrams, AI assistance, and enterprise access controls — a modern alternative to Confluence and Notion.

View details
89
Repo Health
70
Technical
70
Dependency
Built with
TypeScript95%
Updated yesterday
TypeScript
92%
AGPL 3.0

Documenso

Digital Signiture

14,913

Self-hosted, open-source DocuSign alternative with legally binding PDF signatures, multi-party workflows, and a full REST and tRPC API.

View details
93
Repo Health
79
Technical
71
Dependency
Built with
TypeScript92%
Updated today
TypeScript
100%
Other

Dub

Marketing · Analytics

24,676

The open-source link attribution platform for short links, conversion tracking, and affiliate programs — powering 100M+ clicks monthly.

View details
80
Repo Health
78
Technical
62
Dependency
Built with
TypeScript100%
Updated 2 days ago
TypeScript
65%
Other

Epicenter

Knowledge Management · Note Taking · Developer Tools

4,790

A local-first monorepo led by Whispering, an open-source speech-to-text app, built on an MIT toolkit that turns your data into plain Markdown and SQLite files you own instead of a database you rent.

View details
88
Repo Health
90
Technical
68
Dependency
Built with
TypeScript65%
Svelte13%
HTML12%
Updated yesterday
TypeScript
97%
Other

Infisical

Security · Devops

29,145

The open-source platform for secrets, certificates, privileged access, and AI agent security — all in one self-hostable system.

View details
91
Repo Health
84
Technical
65
Dependency
Built with
TypeScript97%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search