larvitslugify
Advanced tools
Comparing version 0.10.10 to 0.11.0
{ | ||
"name": "larvitslugify", | ||
"description": "Slugifies even utf-8 chars!", | ||
"version": "0.10.10", | ||
"description": "Slugify string to make them url safe and more", | ||
"version": "0.11.0", | ||
"homepage": "https://github.com/larvit/larvitslugify", | ||
"author": "Lilleman <lilleman@larvit.se>", | ||
"contributors": [ | ||
{ | ||
"name": "pdehaan (https://github.com/pdehaan" | ||
} | ||
], | ||
"repository": { | ||
@@ -19,3 +14,3 @@ "type": "git", | ||
}, | ||
"main": "slug.js", | ||
"main": "index.js", | ||
"keywords": [ | ||
@@ -25,5 +20,2 @@ "slugify", | ||
"string", | ||
"utf8", | ||
"utf-8", | ||
"unicode", | ||
"url" | ||
@@ -34,13 +26,7 @@ ], | ||
}, | ||
"dependencies": { | ||
"unicode": "^0.6.1" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.4.5", | ||
"should": "^8.3.0" | ||
"mocha": "^3.2.0", | ||
"mocha-eslint": "^3.0.1" | ||
}, | ||
"bin": { | ||
"slug": "bin/slug.js" | ||
}, | ||
"license": "MIT" | ||
"license": "ISC" | ||
} |
@@ -5,14 +5,5 @@ [](https://travis-ci.org/larvit/larvitslugify) [](https://david-dm.org/larvit/larvitslugify.svg) | ||
Forked from [slug](https://github.com/dodo/node-slug) and added some pull requests and options. | ||
Slugifies every string, even when it contains unicode! | ||
Make strings url-safe. | ||
- respecting [RFC 3986](https://tools.ietf.org/html/rfc3986) | ||
- Comprehensive tests | ||
- No dependencies (except the unicode table) | ||
- Not in coffee-script (except the tests lol) | ||
- Coerces foreign symbols to their english equivalent | ||
- Works in browser (window.slug) and AMD/CommonJS-flavoured module loaders (except the unicode symbols unless you use browserify but who wants to download a ~2mb js file, right?) | ||
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. | ||
@@ -26,23 +17,15 @@ ``` | ||
```javascript | ||
var slug = require('larvitslugify'), | ||
print = console.log.bind(console, '>') | ||
const slug = require('larvitslugify'); | ||
print(slug('i ♥ unicode')) | ||
// > i-love-unicode | ||
slug('i ♥ unicode'); // > i-love-unicode | ||
slug('unicode ♥ is ☢'); // > unicode-love-is-radioactive | ||
print(slug('unicode ♥ is ☢')) // yes! | ||
// > unicode-love-is-radioactive | ||
// If you prefer something else then `-` as seperator | ||
slug('i ♥ unicode', '_'); // > i_love_unicode | ||
print(slug('i ♥ unicode', '_')) // If you prefer something else then `-` as seperator | ||
// > i_love_unicode | ||
// Change default charmap or use option {charmap:{…}} as 2. argument | ||
slug.charmap['♥'] = 'freaking love' | ||
slug('I ♥ UNICODE')); // > I-freaking-love-UNICODE | ||
slug.charmap['♥'] = 'freaking love' // change default charmap or use option {charmap:{…}} as 2. argument | ||
print(slug('I ♥ UNICODE')) | ||
// > I-freaking-love-UNICODE | ||
print(slug('☏-Number', {lower: true})) // If you prefer lower case | ||
// > telephone-number | ||
print(slug('i <3 unicode')) | ||
// > i-love-unicode | ||
slug('i <3 unicode'); // > i-love-unicode | ||
``` | ||
@@ -53,4 +36,4 @@ | ||
```javascript | ||
// Options is either object or replacement (sets options.replacement) | ||
slug('string', [{options} || 'replacement']); | ||
// Options is either object or whitespaceReplaceChar (sets options.whitespaceReplaceChar) | ||
slug('string', [{options} || 'whitespaceReplaceChar']); | ||
``` | ||
@@ -62,49 +45,12 @@ | ||
slug('string', { | ||
'replacement': '-', // Replace spaces with replacement | ||
'symbols': true, // Replace unicode symbols or not | ||
'remove': /[d]/g, // Regex to remove characters | ||
'lower': true, // Result in lower case | ||
'charmap': {'Ä': 'ae'}, // Replace special characters | ||
'multicharmap': {'ð': 'oi'}, // Replace multi-characters | ||
'save': ['*', 'ð'], // Do not replace these characters, also takes a string | ||
'wordLimit': 5 // Limits the amount of words to this number | ||
'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 | ||
//'wordLimit': 5 // Limits the amount of words to this number (Currently not supported) | ||
}); | ||
``` | ||
### Option modes | ||
```javascript | ||
slug.defaults.mode ='pretty'; | ||
slug.defaults.modes['rfc3986'] = { | ||
'replacement': '-', | ||
'symbols': true, | ||
'remove': null, | ||
'lower': true, | ||
'charmap': slug.charmap, | ||
'multicharmap': slug.multicharmap | ||
}; | ||
slug.defaults.modes['pretty'] = { | ||
'replacement': '-', | ||
'symbols': true, | ||
'remove': /[.]/g, | ||
'lower': false, | ||
'charmap': slug.charmap, | ||
'multicharmap': slug.multicharmap | ||
}; | ||
``` | ||
## Browser | ||
When using browserify you might want to remove the symbols table from your bundle by using `--ignore` similar to this: | ||
```bash | ||
# Generates a standalone slug browser bundle: | ||
browserify slug.js --ignore unicode/category/So -s slug > slug-browser.js | ||
``` | ||
When using webpack you can use: | ||
```javascript | ||
externals: { | ||
'unicode/category/So': '{}', | ||
} | ||
``` | ||
In your webpack config to replace the require with an empty object stub. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
0
26925
9
546
53
1
1
- Removedunicode@^0.6.1
- Removedbufferjs@3.0.1(transitive)
- Removedbufferstream@0.6.2(transitive)
- Removedbuffertools@2.1.6(transitive)
- Removedunicode@0.6.1(transitive)