joplin/packages/fork-uslug
Henry Heino 9dd82259c6
Desktop: Fixes #12105: Link to header: Move the Markdown editor cursor to the location of the link target (#12118)
2025-04-17 13:02:13 +01:00
..
lib Desktop: Fixes #12105: Link to header: Move the Markdown editor cursor to the location of the link target (#12118) 2025-04-17 13:02:13 +01:00
LICENSE Tools: Use Yarn 3 to manage monorepo (#5833) 2021-12-20 15:08:43 +00:00
README.md Desktop: Fixes #12105: Link to header: Move the Markdown editor cursor to the location of the link target (#12118) 2025-04-17 13:02:13 +01:00
index.js Desktop: Fixes #12105: Link to header: Move the Markdown editor cursor to the location of the link target (#12118) 2025-04-17 13:02:13 +01:00
jest.config.js Desktop: Fixes #12105: Link to header: Move the Markdown editor cursor to the location of the link target (#12118) 2025-04-17 13:02:13 +01:00
package.json Desktop: Fixes #12105: Link to header: Move the Markdown editor cursor to the location of the link target (#12118) 2025-04-17 13:02:13 +01:00
tsconfig.json Desktop: Fixes #12105: Link to header: Move the Markdown editor cursor to the location of the link target (#12118) 2025-04-17 13:02:13 +01:00

README.md

Uslug.js


Modified for Joplin:

  • Added support for emojis - "🐶🐶🐶🐱" => "dogdogdogcat"
  • Smaller package size: Removed dependencies on functionality that's now built-in to JavaScript (Unicode normalization, Unicode character class regular expressions).
  • Types: Migrated to TypeScript.

Permissive slug generator that works with unicode. We keep only characters from the categories Letter, Number and Separator (see Unicode Categories) and the common CJK Unified Ideographs as defined in the version 6.0.0 of the Unicode specification.

Inspired by unicode-slugify. Note that this slug generator is different from node-slug which focus on translating unicode characters to english or latin equivalent.

Quick Examples

uslug('Быстрее и лучше!') // 'быстрее-и-лучше'
uslug('汉语/漢語') // '汉语漢語'

uslug('Y U NO', { lower: false })) // 'Y-U-NO'
uslug('Y U NO', { spaces: true })) // 'y u no'
uslug('Y-U|NO', { allowedChars: '|' })) // 'yu|no'

Installation

npm install uslug

Options

uslug(string, options)

Generate a slug for the string passed.

Arguments

  • string - The string you want to slugify.
  • options - An optional object that can contain:
    • allowedChars: a String of chars that you want to be whitelisted. Default: '-_~'.
    • lower: a Boolean to force to lower case the slug. Default: true.
    • spaces: a Boolean to allow spaces. Default: false.

License

This project is distributed under the MIT License. See LICENSE file for more information.