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

url-slug-lite-ts

v1.0.0

Published

Ultra-fast (<1 KB), zero-dependency Unicode URL slugifier with Latin accent transliteration and separator customization.

Readme

url-slug-lite-ts

Ultra-fast, lightweight Unicode URL slugifier with Latin accent transliteration, decamelization, and SEO-friendly truncation in TypeScript with zero dependencies.

npm version npm downloads license bundle size sponsor


💡 Why url-slug-lite-ts?

Creating clean, readable, SEO-optimized URL slugs should not require bloated multi-megabyte libraries:

  • Zero Dependencies: Pure TypeScript implementation with zero external runtime dependencies.
  • Unicode Accent Transliteration: Normalizes accented characters (é -> e, ñ -> n, ü -> u, ç -> c) using standard Unicode NFD decomposition.
  • Smart Decamelization: Splits camelCase and PascalCase words naturally (myAwesomePost -> my-awesome-post).
  • Safe Truncation: Supports maxLength trimming without leaving dangling hyphens or broken words.
  • Dual ESM & CommonJS: Full support for Node.js, modern bundlers (Vite, Next.js, Webpack, esbuild), and edge runtimes (Cloudflare Workers, Deno, Bun).

📦 Installation

# npm
npm install url-slug-lite-ts

# pnpm
pnpm add url-slug-lite-ts

# yarn
yarn add url-slug-lite-ts

# bun
bun add url-slug-lite-ts

🚀 Quick Start

import { slugify } from 'url-slug-lite-ts';

// Standard sentence
slugify('Hello World! Building Modern Web Apps');
// => 'hello-world-building-modern-web-apps'

// Accents & Diacritics
slugify('Café & Crème Brûlée Délicieuse');
// => 'cafe-and-creme-brulee-delicieuse'

// CamelCase & PascalCase
slugify('TypeScript4Life and React19Updates');
// => 'typescript-4-life-and-react-19-updates'

🛠️ Real-World Examples

1. Next.js / Nuxt Blog Post Routing

Generate clean URLs for dynamic CMS pages:

import { slugify } from 'url-slug-lite-ts';

interface ArticleInput {
  title: string;
  category: string;
}

export function generateArticleSlug(article: ArticleInput): string {
  const categorySlug = slugify(article.category);
  const titleSlug = slugify(article.title, { maxLength: 60 });
  return `/${categorySlug}/${titleSlug}`;
}

const url = generateArticleSlug({
  category: 'Web Development',
  title: 'Top 10 Zero-Dependency NPM Packages You Must Use in 2026!'
});
console.log(url);
// => '/web-development/top-10-zero-dependency-npm-packages-you-must-use-in-2026'

2. E-Commerce Product SKU & Slug Generation

import { slugify } from 'url-slug-lite-ts';

const product = {
  name: 'Sony WH-1000XM5 Wireless Noise-Canceling Headphones (Black)',
  id: 'prod_98765'
};

const productSlug = `${slugify(product.name, { maxLength: 40 })}-${product.id}`;
console.log(productSlug);
// => 'sony-wh-1000xm5-wireless-noise-canceling-prod_98765'

3. File System Sanitization

Clean user-uploaded filenames before storing in S3 or local disk:

import { slugify } from 'url-slug-lite-ts';

export function sanitizeFileName(originalName: string): string {
  const ext = originalName.slice(originalName.lastIndexOf('.'));
  const base = originalName.slice(0, originalName.lastIndexOf('.'));
  return `${slugify(base, { separator: '_' })}${ext.toLowerCase()}`;
}

console.log(sanitizeFileName('My Financial Report (Q3 2026) — Final Draft.PDF'));
// => 'my_financial_report_q3_2026_final_draft.pdf'

4. Custom Separators and Preserved Casing

import { slugify } from 'url-slug-lite-ts';

// Custom underscore separator
slugify('Database Migration Step 1', { separator: '_' });
// => 'database_migration_step_1'

// Preserving uppercase formatting
slugify('ISO Standards Code 9001', { lowercase: false });
// => 'ISO-Standards-Code-9001'

📖 API Reference

slugify(input, options?)

Converts any arbitrary text string into a clean URL slug.

  • Parameters:
    • input (string): The source text to format.
    • options (SlugOptions, optional): Configuration options.
  • Returns: string (formatted slug).

Options (SlugOptions):

| Option | Type | Default | Description | |---|---|---|---| | separator | string | '-' | String used to separate words | | lowercase | boolean | true | Whether to convert characters to lowercase | | decamelize | boolean | true | Split camelCase and PascalCase words with spaces before slugifying | | strict | boolean | true | Strips all non-alphanumeric characters (except separator) | | maxLength | number | undefined | Maximum length of resulting slug without trailing separators |


🏷️ TypeScript Interfaces

export interface SlugOptions {
  /**
   * Character used to replace whitespace and special characters.
   * @default '-'
   */
  separator?: string;

  /**
   * Whether to transform the resulting slug to lowercase.
   * @default true
   */
  lowercase?: boolean;

  /**
   * Whether to split camelCase or PascalCase phrases into words.
   * @default true
   */
  decamelize?: boolean;

  /**
   * Removes symbols, punctuation, and non-alphanumeric characters.
   * @default true
   */
  strict?: boolean;

  /**
   * Truncates the slug to a maximum character length without leaving trailing separators.
   */
  maxLength?: number;
}

🧪 Testing

Every release is tested with 100% test coverage using Vitest:

npm test

💖 Support the Project

If url-slug-lite-ts kept your URLs clean and SEO-friendly, please consider sponsoring:

👉 Sponsor @Piratha97 on GitHub Sponsors


📄 License

MIT © 2026 Pirapaakaran Pirathapan