slugify-advanced
v1.0.6
Published
[DEPRECATED] Advanced, SEO-friendly, locale-aware string slugification for URLs. TypeScript, zero runtime deps.
Downloads
21
Maintainers
Readme
⚠️ DEPRECATED
This package is no longer maintained.
For slug generation with advanced features, please use one of these alternatives:
@sindresorhus/slugify- Modern slugify with great language supportslug- Mature library with custom character mappinglight-slug-emoji- If you specifically need emoji handling
Original README below:
slugify-advanced
Advanced, SEO-friendly, locale-aware string slugification for URLs. TypeScript, zero runtime dependencies.
Features
- SEO-friendly: Clean, predictable slugs for URLs.
- Locale-aware: Built-in transliteration for common European characters.
- Highly customizable: Control separators, case, replacements, strictness, stop words, and more.
- TypeScript-first: Full types and JSDoc.
- Zero runtime dependencies.
Installation
npm install slugify-advancedUsage
import { slugify } from 'slugify-advanced';
slugify('Hello World!'); // 'hello-world'
slugify('für Straße'); // 'fuer-strasse'
slugify('Crème brûlée', { separator: '_' }); // 'creme_brulee'API
slugify(input: string, options?: SlugifyOptions): string
Converts a string into a URL-friendly slug with advanced customization options.
Options
| Option | Type | Default | Description |
| -------------------- | ------------------------------------------------- | ----------- | ----------------------------------------------------------------------------------- |
| separator | string | '-' | Character used to join words and replace invalid character sequences. |
| lowercase | boolean | true | Whether to convert the result to lowercase. |
| customReplacements | Record<string, string> or Map<string, string> | {} | Custom character replacements to apply before any other processing. |
| locale | boolean | true | Enable built-in locale transliterations for common European characters. |
| strict | boolean | false | If true, only allows alphanumeric and separator. If false, also allows underscores. |
| maxLength | number | undefined | Maximum length of the resulting slug. No trailing separator after truncation. |
| removeStopWords | boolean or string[] | false | Remove common English stop words (or custom list). |
Examples
slugify('The quick brown fox jumps over the lazy dog', { removeStopWords: true });
// 'quick-brown-fox-jumps-lazy-dog'
slugify('foo_bar-baz!', { strict: true });
// 'foo-bar-baz'
slugify('foo bar baz', { separator: '', customReplacements: { foo: 'zap' } });
// 'zapbarbaz'
slugify('Äpfel & Öl!', { lowercase: false, separator: '_', locale: true });
// 'Aepfel_Oel'
slugify('foo bar baz', { maxLength: 7 });
// 'foo-bar'Locale Support
If locale: true (default), the following mappings are applied:
- German:
ä → ae,ö → oe,ü → ue,ß → ss - French:
à → a,â → a,æ → ae,ç → c,é → e,è → e,ê → e,ë → e,î → i,ï → i,ô → o,œ → oe,ù → u,û → u,ü → u,ÿ → y - Spanish:
á → a,í → i,ñ → n,ó → o,ú → u - Scandinavian:
å → a,ø → o - Other:
č → c,š → s,ž → z,ł → l, etc.
See src/constants.ts for the full mapping.
Order of Operations
- Input check: Throws if not a string. Trims input. Returns
''if empty. - Custom replacements: Applies user-defined replacements (longest keys first).
- Case conversion: Applies
lowercaseif enabled. - Locale transliteration: Applies built-in mappings if
locale: true. - Unicode normalization: Removes diacritics.
- Stop word removal: Removes stop words if enabled.
- Whitespace replacement: Replaces whitespace with
separator. - Disallowed character removal: Removes unwanted characters based on
strict. - Collapse separators: Collapses consecutive separators.
- Trim separators: Trims leading/trailing separators.
- Max length: Truncates to
maxLength(no trailing separator). - Return: Returns the slug.
License
MIT
Contributing
Contributions are welcome! Please open issues or pull requests.
