0.0.2 • Published 3 years ago

elegant-slug v0.0.2

Weekly downloads
2
License
MIT
Repository
-
Last release
3 years ago

elegant-slug

🧹 Elegant & SEO-friendly slugger for URLs

Installation

Using npm:

npm install elegant-slug

Using yarn:

yarn add elegant-slug

Usage

import slug from 'elegant-slug';

slug('déjà vu');
// 'deja-vu'

slug('some title', { separator: 'underscore' });
// 'some_title'

slug('this is a really long title and it should not exceed 50 characters', {
  maxLength: 50,
});
// 'this-is-a-really-long-title'

slug('LOWERCASE---PLEASE!', {
  letterCase: 'lowercase',
});
// 'lowercase-please'

slug('مرحبا مرحبا', {
  charMap: {
    ا: 'a',
    ب: 'b',
    ح: 'h',
    ر: 'r',
    م: 'm',
  },
});
// mrhba-mrhba

slug('this is the title', { unique: true });
// this-is-the-title-fqgkhg5dra2

API Documentation

slug(str: string, options?: Options)

str

String to be converted into a slug

options (optional)

Additional options to format the slug. See below for the available options.

Options

NameDefaultTypeDescription
separator'hyphen''hyphen' | 'underscore'The separator symbol that will be used in between the concatenated strings. hyphen uses the - symbol while underscore uses the _ symbol.
maxLengthnumberThe maximum length of the converted slug. Once exceeding the specified length, the words get cropped out.
letterCase'lowercase' | 'uppercase' | 'capitalize'The letter case the slug should be transformed into. If nothing is provided, the original casing will be used.
uniquebooleanIf set to true, a unique id generated using uniqid will be appended to the end of the slug.
charMapRecord<string, string>A map of key-value pairs that are used to replace occurrences with the given values.