New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

standard-slugify

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

standard-slugify

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

  • 4.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 30 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc