Skip to main content
Home

Built and signed on GitHub Actions

Deno library for converting arbitrary strings into valid slugs

This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
100%
Published
a year ago (1.2.1)

slug

Deno library for converting arbitrary strings into valid slugs

import { slug } from "https://deno.land/x/slug/mod.ts";

console.log(slug("some string")); // some-string
console.log(slug("some string", "_")); // some_string
console.log(slug("I ♥ UNICODE")); // i-love-unicode
console.log(slug("I ♥ UNICODE", { lower: false })); // I-love-UNICODE

Options

slug("some ƒÚÑķÝ and ☢ string", {
  replacement: "-", // replace spaces with replacement character (defaults to `-`)
  remove: /[^\w\s$*_+~.()'"!\-:@]+/g, // remove characters that match regex (defaults to `/[^\w\s$*_+~.()'"!\-:@]+/g`)
  lower: true, // convert to lower case (defaults to `true`)
  strict: false, // strip special characters except replacement (defaults to `false`)
  locale: "vi", // language code of the locale to use (defaults to `vi`)
  trim: true, // trim leading and trailing replacement chars (defaults to `true`)
  extends: { "☢": "nuclear" }, // extend default unicode character set (defaults to `{}`)
}); // some-funky-and-nuclear-string

Propers

Fork of https://github.com/dunosaurs/slug for publishing to JSR

Heavily inspired by: Slug and Slugify

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@annervisser/slug

Import symbol

import * as slug from "@annervisser/slug";
or

Import directly with a jsr specifier

import * as slug from "jsr:@annervisser/slug";

Add Package

pnpm i jsr:@annervisser/slug
or (using pnpm 10.8 or older)
pnpm dlx jsr add @annervisser/slug

Import symbol

import * as slug from "@annervisser/slug";

Add Package

yarn add jsr:@annervisser/slug
or (using Yarn 4.8 or older)
yarn dlx jsr add @annervisser/slug

Import symbol

import * as slug from "@annervisser/slug";

Add Package

vlt install jsr:@annervisser/slug

Import symbol

import * as slug from "@annervisser/slug";

Add Package

npx jsr add @annervisser/slug

Import symbol

import * as slug from "@annervisser/slug";

Add Package

bunx jsr add @annervisser/slug

Import symbol

import * as slug from "@annervisser/slug";