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 🙏

© 2024 – Pkg Stats / Ryan Hefner

standard-slugify

v4.0.0

Published

Converts a string into a slug safe for URLs and filenames. Supports Latin, Greek and Cyrillic scripts.

Downloads

113

Readme

standard-slugify

Converts a string into a slug safe for URLs and filenames. Supports Latin, Greek and Cyrillic scripts.

Installing

npm install standard-slugify

API

standardSlugify(string, { keepCase, replacements })

Returns a slug of the given string.

The slug is in lowercase, unless the keepCase option is set to true.

import standardSlugify from "standard-slugify";

standardSlugify("Where is your résumé?");
// => "where-is-your-resume"

standardSlugify("toString()", { keepCase: false });
// => "tostring"

standardSlugify("toString()", { keepCase: true });
// => "toString"

standardSlugify("Æthelflæd", { keepCase: true });
// => "Aethelflaed"

standardSlugify("ÆTHELFLÆD", { keepCase: true });
// => "AETHELFLAED"

To specify custom replacements, pass as the replacements option an array of [regexp, replacement] pairs.

import standardSlugify from "standard-slugify";

standardSlugify("₿ raising, € falling", {
  replacements: [
    ["€", "eur"], // EURO SIGN
    ["₿", "btc"], // BITCOIN SIGN
  ],
});
// => "btc-raising-eur-falling"

// Replacements can be matched with regular expressions,
// e.g., transliterating Ukrainian according to ISO/IEC 7501-3
standardSlugify("Єгипет, Їжак, Йорданія, Югославія, Ямайка", {
  replacements: [
    [/(?<=^|\P{L})Є/, "YE"], // Є as the first letter of a word
    [/(?<=^|\P{L})Ї/, "YI"], // Ї as the first letter of a word
    ["Г", "H"], // Г in any position
    ["И", "Y"], // И in any position
    [/(?<=^|\P{L})Й/, "Y"], // Й as the first letter of a word
    [/(?<=^|\P{L})Ю/, "YU"], // Ю as the first letter of a word
    [/(?<=^|\P{L})Я/, "YA"], // Я as the first letter of a word
  ],
});
// => "yehypet-yizhak-yordaniia-yuhoslaviia-yamaika"

Details

The slug is created by replacing characters according to the following rules and standards:

  1. If any custom replacements are given, they are applied before the default replacements
  2. Letters from ISO-8859-1,2,3,4,5,7,9,10,13,14,15,16, MES-1 and WGL4 (every Latin, Greek and Cyrillic letter actually used in keyboard layouts or fonts) are transliterated to ASCII:
    • Latin or Cyrillic letters are transliterated according to ISO/IEC 7501-3
    • Greek letters are transliterated according to ISO 843
  3. Letters are lowercased, unless the keepCase option is set to true
  4. Characters with the White_Space property or in the Dash_Punctuation (Pd) General Category of Unicode and Control Codes with semantics in Unicode (§ 23.1), such as HT (\t) and LF (\n), are converted to HYPHEN-MINUS (-)
  5. Characters than are not an ASCII letter ([A-Za-z]), a number ([0-9]), a LOWLINE (_) or a HYPHEN-MINUS (-) are removed
  6. Leading, trailing and duplicate HYPHEN-MINUS (-) characters are removed