npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

slug-from-text

v1.0.4

Published

Generate URL-friendly slugs from text. Zero dependencies.

Readme

slug-from-text

Generate URL-friendly slugs from any text. Zero dependencies. TypeScript-first.

npm license build

Features

  • Converts any text to a clean, URL-safe slug
  • Normalizes accented Latin letters to ASCII (ée, ßss, æae, etc.)
  • Configurable separator (-, _, or none), max length, locale-aware lowercase
  • Written in TypeScript — ships with full type declarations
  • Zero runtime dependencies
  • Works in Node.js, Deno, Bun, and modern browsers
  • ESM + CommonJS dual build

Install

npm install slug-from-text
# or
pnpm add slug-from-text
# or
yarn add slug-from-text

Usage

import { slug } from 'slug-from-text'

slug('Hello World!')                              // 'hello-world'
slug('Café & Bar')                                // 'cafe-bar'
slug('Über groß')                                 // 'uber-gross'
slug('Hello World!', { separator: '_' })          // 'hello_world'
slug('Hello World!', { separator: '' })           // 'helloworld'
slug('Hello World!', { lowercase: false })        // 'Hello-World'
slug('Very long title here', { maxLength: 10 })   // 'very-long'
slug('Istanbul', { locale: 'tr' })                // locale-aware lowercase

CommonJS (require) is also supported:

const { slug } = require('slug-from-text')

slug('Hello World!') // 'hello-world'

API

slug(text: string, options?: SlugOptions): string

Converts text to a URL-friendly slug.

Returns '' for empty strings, whitespace-only strings, and non-string values.

Options

| Option | Type | Default | Description | |---|---|---|---| | separator | '-' \| '_' \| '' | '-' | Character used to replace spaces and other separators | | lowercase | boolean | true | Convert to lowercase before processing | | removeSpecialChars | boolean | true | Remove non-word characters (punctuation, symbols) | | maxLength | number | — | Trim result to this length; trailing separators are removed | | locale | string \| false | — | Locale for toLocaleLowerCase() (e.g. 'tr' for Turkish) |

TypeScript types

The package exports the following types:

import { slug, type SlugOptions, type SlugSeparator } from 'slug-from-text'
  • SlugOptions — options object for the slug function
  • SlugSeparator — union type '-' | '_' | ''

Normalization details

Accented Latin characters are normalized via Unicode NFD decomposition + diacritic strip, with additional manual mappings:

| Input | Output | | Input | Output | |---|---|---|---|---| | é ö ñ | e o n | | ß | ss | | æ / Æ | ae / AE | | œ / Œ | oe / OE | | ı | i | | İ | I |

Separators and whitespace:

  • Consecutive whitespace is collapsed and replaced by separator
  • Leading and trailing separators are always trimmed

Development

git clone https://github.com/MaxGrushevsky/slug.git
cd slug
npm install

npm run build         # compile to dist/
npm test              # run tests once
npm run test:watch    # run tests in watch mode
npm run typecheck     # TypeScript type-check only

License

MIT