2.0.1 • Published 4 years ago

larvitslugify v2.0.1

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

Build Status

larvitslugify

Make strings url-safe.

Vanilla javascript, no production dependencies.

Why not use slug? Or slugify? Well, I built this because I wanted a more transparent and powerfull implementation. If I wanted to preserve "/" and change "." to ":" I want to be able to do that, but still have the comfort of everything else being a default slugifier.

npm install larvitslugify

Examples

const { slugify, defaultCharmap } = require('larvitslugify');

slugify('i ♥ unicode'); // > i-love-unicode
slugify('unicode ♥ is ☢'); // > unicode-love-is-radioactive

// If you prefer something else then `-` as seperator
slugify('i ♥ unicode', '_'); // > i_love_unicode

// Change default charmap by passing charmap option as argument
slugify('I ♥ UNICODE', { charmap: { ...defaultCharmap, '♥': 'freaking love' } })); // > I-freaking-love-UNICODE

slugify('i <3 unicode'); // > i-love-unicode

Options

// Options is either object or whitespaceReplaceChar (sets options.whitespaceReplaceChar)
slugify('string', [{options} || 'whitespaceReplaceChar']);

All options

slugify('string', {
	'whitespaceReplaceChar': '-', // Replace spaces with replacement
	'charmap': {'Å': 'A', 'Ö': 'O' ... }, // A complete replacement of the charmap. All characters not in the map will be replaced by the unidentifiedReplaceChar
	'multiCharmap': = {'<3': 'love', '||': 'and'}, // These will be matched before the single chars, also a complete replacement
	'removeMultipleWhitespace': = true, // Will replace all multiple whitespaces with a single one
	'trim': = true, // Run trim() on the string
	'unidentifiedReplaceChar': = '', // If unidentified characters are found they are replaced with this string
	'whitespaces': = [' ', '\t', '\xa0'] // A list of characters identified as whitespaces
	'save': = undefined // Adds a character to the charmap to "save" from being changed or removed. Takes a string of one character or an array of single caracter strings

 //'wordLimit': 5 // Limits the amount of words to this number (Currently not supported)
});

Changelog

2.0.0

  • Rewrote in TypeScript.
2.0.1

4 years ago

2.0.0

4 years ago

1.0.0

6 years ago

0.11.5

6 years ago

0.11.4

7 years ago

0.11.3

7 years ago

0.11.2

8 years ago

0.11.1

8 years ago

0.11.0

8 years ago

0.10.10

9 years ago

0.10.9

9 years ago

0.10.8

9 years ago

0.10.7

10 years ago

0.10.6

10 years ago

0.10.5

10 years ago

0.10.4

10 years ago

0.10.3

10 years ago

0.10.2

10 years ago

0.10.1

10 years ago

0.10.0

10 years ago