https://github.com/danielhaim1/slugify
An all-purpose slug generator that converts text into clean, SEO-friendly slugs. It's ideal for automating anchor IDs in headings and is designed to handle a wide range of languages and special characters.
https://github.com/danielhaim1/slugify
Last synced: 8 months ago
JSON representation
An all-purpose slug generator that converts text into clean, SEO-friendly slugs. It's ideal for automating anchor IDs in headings and is designed to handle a wide range of languages and special characters.
- Host: GitHub
- URL: https://github.com/danielhaim1/slugify
- Owner: danielhaim1
- License: mit
- Created: 2022-11-14T12:20:22.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-09-18T06:58:10.000Z (9 months ago)
- Last Synced: 2025-09-18T08:43:01.763Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 3.83 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Multilang Slugify
[](https://www.npmjs.com/package/@danielhaim/slugify)
[](https://www.npmjs.com/package/@danielhaim/slugify)

Slugify is an all-purpose slug generator that converts text into clean, SEO-friendly slugs. It's ideal for automating anchor IDs in headings and is designed to handle a wide range of languages and special characters.
## Demo
------------
## Supported Languages
Slugify supports a diverse set of languages:
German, Danish, Dutch, Finnish, French, Hungarian, Italian, Norwegian, Portuguese, Romanian, Russian, Spanish, Swedish, Turkish, Greek, Bulgarian, Serbian, Croatian, Czech, Polish, Slovak, Slovenian, Latvian, Lithuanian, Estonian, Persian, Arabic, Hebrew, Hindi, Thai, Chinese, Japanese, Korean, Vietnamese, and Ukrainian, as well as Emoji
## Installation
You can install this module via npm:
```bash
$ npm i @danielhaim/slugify
```
## NPM
```js
import { slugify } from './path/to/slugify/index.js';
const slugifier = new slugify();
console.log(slugifier.generate("Hello World!")); // returns "hello-world"
```
------------
## Examples
### Headings with IDs
Input:
```html
How will mobile commerce impact 2022?
Sophia, Ärztin aus Hamburg
Süße Sophia, schön und klug
```
```js
// Function to generate slugs
function generateSlug(titleElement) {
const titleContent = titleElement.textContent || '';
const slugifier = new slugify();
const slugged = slugifier.generate(titleContent);
return slugged;
}
// Select all heading elements (h1, h2, h3, etc.)
const headingElements = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
headingElements.forEach((headingElement) => {
const slugged = generateSlug(headingElement);
Output:
```html
How will mobile commerce impact 2022?
Sophia, Ärztin aus Hamburg
Süße Sophia, schön und klug
```
### German special characters
```js
const slugifier = new slugify();
slugifier.generate('Ist dein Name Sophia?'); // Output: "ist-dein-name-sophia"
slugifier.generate('Sophia, Ärztin aus Hamburg'); // Output: "sophia-aerztin-aus-hamburg"
slugifier.generate('Wie geht es dir, Sophia?'); // Output: "wie-geht-es-dir-sophia"
slugifier.generate('Süße Sophia, schön und klug'); // Output: "suesse-sophia-schoen-und-klug"
slugifier.generate("Sophia's Geburtstag"); // Output: "sophias-geburtstag"
```
### Additional examples with special characters and delimiters
```js
const slugifier = new slugify();
slugifier.generate('Hello, world!'); // Output: "hello-world"
slugifier.generate('Hello, world!'); // Output: "hello_world"
slugifier.generate('Hello, world!'); // Output: "hello-world"
slugifier.generate('#1 Best in Class'); // Output: "number-1-best-in-class"
slugifier.generate('hello@example.com'); // Output: "hello-at-example-com"
```
## Build Process
```bash
$ npm run build
```
## Test
```bash
$ npm run test
```
## Report Bugs
If you encounter any bugs or issues while using the library, please report them by opening a new issue in the repository's issue tracker.
When reporting a bug, please provide as much detail as possible, including the steps to reproduce the issue and any error messages that you see. I appreciate any contribution to improving this library.