Skip to content

Lightweight slug generation. Browser & Bun / Node.js compatible.

License

Notifications You must be signed in to change notification settings

stacksjs/ts-slug

Repository files navigation

Social Card of this repo

npm version GitHub Actions Commitizen friendly

ts-slug

A powerful TypeScript library for converting text strings into URL-friendly slugs. Whether you're building a blog, CMS, or any application that needs clean, normalized URLs, ts-slug provides a robust solution with excellent multilingual support.

Features

ts-slug offers a range of powerful features:

  • 🌍 Unicode Support - Handles special characters from any language
  • 🔤 Locale-specific Handling - Special support for German, Bulgarian, Serbian, Ukrainian, and more
  • ⚙️ Highly Configurable - Customize replacement characters, case sensitivity, and more
  • 🔄 Multiple Modes - Choose between RFC 3986 compliant or pretty URL formats
  • 📝 TypeScript Native - Full type definitions included
  • 🪶 Zero Dependencies - Lightweight with no external dependencies
  • 🧪 Thoroughly Tested - Comprehensive test suite ensures reliability

Quick Example

import slug from 'ts-slug'
// alternatively
// import { slug } from 'ts-slug'

// Basic usage
slug('Hello World') // 'hello-world'

// With options
slug('Hello World', {
  replacement: '_',
  lower: false
}) // 'Hello_World'

// Multilingual support
slug('こんにちは世界') // 'konnichihasei-jie'
slug('Schöne Grüße', { locale: 'de' }) // 'schoene-gruesse'

Installation

# npm
npm install ts-slug

# yarn
yarn add ts-slug

# pnpm
pnpm add ts-slug

# bun
bun install ts-slug

Testing

bun test

Changelog

Please see our releases page for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Community

For help, discussion about best practices, or any other conversation that would benefit from being searchable:

Discussions on GitHub

For casual chit-chat with others using this package:

Join the Stacks Discord Server

Postcardware

"Software that is free, but hopes for a postcard." We love receiving postcards from around the world showing where Stacks is being used! We showcase them on our website too.

Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎

Credits

Sponsors

We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.

License

The MIT License (MIT). Please see LICENSE for more information.

Made with 💙