slugify
import { slugify } from "jsr:@ende/text/unstable-slugify";function · experimental
function slugify(input: string, options?: Partial<SlugifyOptions>): stringConverts a string into a slug.
input: stringThe string that is going to be converted into a slug
options?: Partial<SlugifyOptions>The options for the slugify function
Returns
The string as a slug
Example: Basic usage
import { slugify } from "@ende/text/unstable-slugify";
import { assertEquals } from "@ende/assert";
assertEquals(slugify("Hello, world!"), "hello-world");
assertEquals(slugify("Συστημάτων Γραφής"), "συστημάτων-γραφής");
Example: With transliteration
import { NON_ASCII_REGEXP, slugify } from "@ende/text/unstable-slugify";
import { assertEquals } from "@ende/assert";
// a custom transliteration function
const transliterate = (s: string) => s.replaceAll("ß", "ss");
assertEquals(
slugify("Straße", { transliterate, strip: NON_ASCII_REGEXP }),
"strasse",
);