node-slugify
Advanced tools
Comparing version 0.0.2 to 0.0.3
91
index.js
@@ -1,46 +0,45 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = function (string, options) { | ||
if (!string) return ''; | ||
if (!string) return '' | ||
options = options || {}; | ||
var maintainCase = options.maintainCase; | ||
var replacement = options.replacement || '-'; | ||
var maxLen = options.maxLen || 80; | ||
var prevdash = false; | ||
var sb = [ ]; | ||
var url; | ||
var c; | ||
options = options || {} | ||
var maintainCase = options.maintainCase | ||
var replacement = options.replacement || '-' | ||
var maxLen = options.maxLen || 80 | ||
var prevdash = false | ||
var sb = [ ] | ||
var c | ||
for (var i = 0; i < string.length; ++i) { | ||
c = string[i]; | ||
c = string[i] | ||
if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) { | ||
sb.push(c); | ||
prevdash = false; | ||
sb.push(c) | ||
prevdash = false | ||
} else if (c >= 'A' && c <= 'Z') { | ||
if (maintainCase) { | ||
sb.push(c); | ||
sb.push(c) | ||
} else { | ||
sb.push(c.toLowerCase()); | ||
sb.push(c.toLowerCase()) | ||
} | ||
prevdash = false; | ||
prevdash = false | ||
} else if (c === ' ' || c === ',' || c === '.' || c === '/' || | ||
c === '\\' || c === '-' || c === '_' || c === '=') { | ||
if (!prevdash && sb.length > 0) { | ||
sb.push(replacement); | ||
prevdash = true; | ||
sb.push(replacement) | ||
prevdash = true | ||
} | ||
} else if (c.charCodeAt(0) >= 128) { | ||
var remapped = remapInternationalCharToAscii(c); | ||
var remapped = remapInternationalCharToAscii(c) | ||
if (remapped) { | ||
sb.push(remapped); | ||
prevdash = false; | ||
sb.push(remapped) | ||
prevdash = false | ||
} | ||
} | ||
if (sb.length === maxLen) break; | ||
if (sb.length === maxLen) break | ||
} | ||
if (prevdash) { | ||
return sb.join('').substring(0, sb.length - 1); | ||
return sb.join('').substring(0, sb.length - 1) | ||
} else { | ||
return sb.join(''); | ||
return sb.join('') | ||
} | ||
@@ -50,24 +49,24 @@ } | ||
function remapInternationalCharToAscii (c) { | ||
if ('àåáâãåa'.indexOf(c) !== -1) return 'a'; | ||
else if ('èéêe'.indexOf(c) !== -1) return 'e'; | ||
else if ('ìíîïi'.indexOf(c) !== -1) return 'i'; | ||
else if ('òóôõøoð'.indexOf(c) !== -1) return 'o'; | ||
else if ('ùúûuu'.indexOf(c) !== -1) return 'u'; | ||
else if ('çccc'.indexOf(c) !== -1) return 'c'; | ||
else if ('zzž'.indexOf(c) !== -1) return 'z'; | ||
else if ('ssšs'.indexOf(c) !== -1) return 's'; | ||
else if ('ñn'.indexOf(c) !== -1) return 'n'; | ||
else if ('ýÿ'.indexOf(c) !== -1) return 'y'; | ||
else if ('gg'.indexOf(c) !== -1) return 'g'; | ||
else if (c === 'r') return 'r'; | ||
else if (c === 'l') return 'l'; | ||
else if (c === 'd') return 'd'; | ||
else if (c === 'ä') return 'ae'; | ||
else if (c === 'ö') return 'oe'; | ||
else if (c === 'ü') return 'ue'; | ||
else if (c === 'ß') return 'ss'; | ||
else if (c === 'Þ') return 'th'; | ||
else if (c === 'h') return 'h'; | ||
else if (c === 'j') return 'j'; | ||
else return ''; | ||
if ('àåáâãåa'.indexOf(c) !== -1) return 'a' | ||
else if ('èéêe'.indexOf(c) !== -1) return 'e' | ||
else if ('ìíîïi'.indexOf(c) !== -1) return 'i' | ||
else if ('òóôõøoð'.indexOf(c) !== -1) return 'o' | ||
else if ('ùúûuu'.indexOf(c) !== -1) return 'u' | ||
else if ('çccc'.indexOf(c) !== -1) return 'c' | ||
else if ('zzž'.indexOf(c) !== -1) return 'z' | ||
else if ('ssšs'.indexOf(c) !== -1) return 's' | ||
else if ('ñn'.indexOf(c) !== -1) return 'n' | ||
else if ('ýÿ'.indexOf(c) !== -1) return 'y' | ||
else if ('gg'.indexOf(c) !== -1) return 'g' | ||
else if (c === 'r') return 'r' | ||
else if (c === 'l') return 'l' | ||
else if (c === 'd') return 'd' | ||
else if (c === 'ä') return 'ae' | ||
else if (c === 'ö') return 'oe' | ||
else if (c === 'ü') return 'ue' | ||
else if (c === 'ß') return 'ss' | ||
else if (c === 'Þ') return 'th' | ||
else if (c === 'h') return 'h' | ||
else if (c === 'j') return 'j' | ||
else return '' | ||
} |
{ | ||
"name": "node-slugify", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Simple and useful function for generating friendly url/slug.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "./node_modules/mocha/bin/mocha ./test/*", | ||
"test": "standard && ./node_modules/mocha/bin/mocha ./test/*", | ||
"test-travis": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec ./test/*" | ||
@@ -12,3 +12,3 @@ }, | ||
"type": "git", | ||
"url": "https: //github.com/10uei011/node-slugify" | ||
"url": "https://github.com/10uei011/node-slugify" | ||
}, | ||
@@ -27,4 +27,5 @@ "keywords": [ | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.2.0" | ||
"mocha": "^3.2.0", | ||
"standard": "^9.0.2" | ||
} | ||
} |
@@ -113,3 +113,2 @@ 'use strict' | ||
// stackoverflow.com/questions/1642028/why_is_india_great | ||
@@ -130,7 +129,2 @@ it('Why is india great: “-->”?', () => { | ||
// stackoverflow.com/questions/6430448/why-doesnt-gcc-optimize-aaaaaa-to-aaaaaa | ||
@@ -137,0 +131,0 @@ it('Why doesn\'t GCC optimize a*a*a*a*a*a to (a*a*a)*(a*a*a)?', () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
0
9493
4
194