Tiny utility to create, compare, and validate URL-friendly slugs from strings.
- 📝 Convert any string to a clean, URL-friendly slug
- 🔍 Compare two strings by their slugified versions
- ✅ Validate if a string is a valid slug
- ⚙️ Supports custom separators, lowercase option, and fallback values
- 🚀 Works in Node.js, Deno, and browsers
-
Deno:
deno add jsr:@dep/slug
-
Node.js (18+) or Browsers:
npx jsr add @dep/slug
Then import as an ES module:
import { compare, isSlug, slug, type SlugOptions } from "@dep/slug";
import { compare, isSlug, slug } from "@dep/slug";
// Convert string to slug
slug("Hello World!"); // 'hello-world'
// Compare two strings by slug
compare("Hello World!", "hello-world"); // true
// Validate a slug
isSlug("my-awesome-slug"); // true
isSlug("Invalid Slug!"); // false
// Options
slug("Hola Mundo", { separator: "_", lowercase: false }); // 'Hola_Mundo'MIT License – see LICENSE for details.
Author: Estarlin R (estarlincito.com)