larvitslugify
Advanced tools
Comparing version 0.11.4 to 0.11.5
220
index.js
'use strict'; | ||
exports = module.exports = function slugify(str, options) { | ||
let whitespaces = [], | ||
charmap = {}, | ||
prevWS = false; | ||
let whitespaces = []; | ||
let charmap = {}; | ||
let prevWS = false; | ||
if (typeof options === 'string') { | ||
options = {'whitespaceReplaceChar': options}; | ||
options = {whitespaceReplaceChar: options}; | ||
} | ||
if ( ! options) options = {}; | ||
if (options.charmap === undefined) options.charmap = exports.charmap; | ||
if (options.multiCharmap === undefined) options.multiCharmap = exports.multiCharmap; | ||
if (options.removeMultipleWhitespace === undefined) options.removeMultipleWhitespace = true; | ||
if (options.trim === undefined) options.trim = true; | ||
if (options.unidentifiedReplaceChar === undefined) options.unidentifiedReplaceChar = exports.unidentifiedReplaceChar; | ||
if (options.whitespaceReplaceChar === undefined) options.whitespaceReplaceChar = exports.whitespaceReplaceChar; | ||
if (options.whitespaces === undefined) options.whitespaces = exports.whitespaces; | ||
if (!options) options = {}; | ||
if (options.charmap === undefined) options.charmap = exports.charmap; | ||
if (options.multiCharmap === undefined) options.multiCharmap = exports.multiCharmap; | ||
if (options.removeMultipleWhitespace === undefined) options.removeMultipleWhitespace = true; | ||
if (options.trim === undefined) options.trim = true; | ||
if (options.unidentifiedReplaceChar === undefined) options.unidentifiedReplaceChar = exports.unidentifiedReplaceChar; | ||
if (options.whitespaceReplaceChar === undefined) options.whitespaceReplaceChar = exports.whitespaceReplaceChar; | ||
if (options.whitespaces === undefined) options.whitespaces = exports.whitespaces; | ||
@@ -28,3 +28,3 @@ // Copy the charmap object so we do not screw up the original one | ||
if (options.trim === true) { | ||
str = str.trim(); | ||
str = str.trim(); | ||
} | ||
@@ -34,7 +34,7 @@ | ||
if (options.save) { | ||
if ( ! Array.isArray(options.save)) { | ||
if (!Array.isArray(options.save)) { | ||
options.save = [options.save]; | ||
} | ||
for (let i = 0; options.save[i] !== undefined; i ++) { | ||
for (let i = 0; options.save[i] !== undefined; i++) { | ||
charmap[options.save[i]] = options.save[i]; | ||
@@ -47,4 +47,4 @@ } | ||
// from the charmap further down | ||
for (let i = 0; options.whitespaces[i] !== undefined; i ++) { | ||
const whitespace = options.whitespaces[i]; | ||
for (let i = 0; options.whitespaces[i] !== undefined; i++) { | ||
const whitespace = options.whitespaces[i]; | ||
@@ -63,17 +63,17 @@ if (charmap[whitespace] === undefined) { | ||
str = str.split(''); | ||
for (let i = 0; str[i] !== undefined; i ++) { | ||
const thisStr = str[i]; | ||
for (let i = 0; str[i] !== undefined; i++) { | ||
const thisStr = str[i]; | ||
// Whitespace found! | ||
if (whitespaces.indexOf(thisStr) !== - 1) { | ||
if (whitespaces.indexOf(thisStr) !== -1) { | ||
if (prevWS === true && options.removeMultipleWhitespace === true) { | ||
str[i] = ''; | ||
str[i] = ''; | ||
} else { | ||
str[i] = options.whitespaceReplaceChar; | ||
str[i] = options.whitespaceReplaceChar; | ||
} | ||
prevWS = true; | ||
prevWS = true; | ||
// No whitespace found | ||
} else { | ||
str[i] = charmap[thisStr] || options.unidentifiedReplaceChar; | ||
str[i] = charmap[thisStr] || options.unidentifiedReplaceChar; | ||
@@ -84,3 +84,3 @@ // If the previous character was a whitespace and the current should be ignored, set prevWS to true again | ||
} else { | ||
prevWS = false; | ||
prevWS = false; | ||
} | ||
@@ -90,3 +90,3 @@ } | ||
str = str.join(''); | ||
str = str.join(''); | ||
@@ -96,6 +96,6 @@ return str; | ||
exports.unidentifiedReplaceChar = ''; | ||
exports.whitespaceReplaceChar = '-'; | ||
exports.unidentifiedReplaceChar = ''; | ||
exports.whitespaceReplaceChar = '-'; | ||
exports.whitespaces = [' ', '\t', '\xa0']; // Last being a non breaking whitespace | ||
exports.whitespaces = [' ', '\t', '\xa0']; // Last being a non breaking whitespace | ||
@@ -108,90 +108,90 @@ // Taken from https://github.com/dodo/node-slug/blob/master/slug.js | ||
// ASCII alphabet and numbers | ||
'0': '0', '1': '1', '2': '2', '3': '3', '4': '4', '5': '5', '6': '6', | ||
'7': '7', '8': '8', '9': '9', | ||
'A': 'A', 'B': 'B', 'C': 'C', 'D': 'D', 'E': 'E', 'F': 'F', 'G': 'G', | ||
'H': 'H', 'I': 'I', 'J': 'J', 'K': 'K', 'L': 'L', 'M': 'M', 'N': 'N', | ||
'O': 'O', 'P': 'P', 'Q': 'Q', 'R': 'R', 'S': 'S', 'T': 'T', 'U': 'U', | ||
'V': 'V', 'W': 'W', 'X': 'X', 'Y': 'Y', 'Z': 'Z', | ||
'a': 'a', 'b': 'b', 'c': 'c', 'd': 'd', 'e': 'e', 'f': 'f', 'g': 'g', | ||
'h': 'h', 'i': 'i', 'j': 'j', 'k': 'k', 'l': 'l', 'm': 'm', 'n': 'n', | ||
'o': 'o', 'p': 'p', 'q': 'q', 'r': 'r', 's': 's', 't': 't', 'u': 'u', | ||
'v': 'v', 'w': 'w', 'x': 'x', 'y': 'y', 'z': 'z', | ||
0: '0', 1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', | ||
7: '7', 8: '8', 9: '9', | ||
A: 'A', B: 'B', C: 'C', D: 'D', E: 'E', F: 'F', G: 'G', | ||
H: 'H', I: 'I', J: 'J', K: 'K', L: 'L', M: 'M', N: 'N', | ||
O: 'O', P: 'P', Q: 'Q', R: 'R', S: 'S', T: 'T', U: 'U', | ||
V: 'V', W: 'W', X: 'X', Y: 'Y', Z: 'Z', | ||
a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', g: 'g', | ||
h: 'h', i: 'i', j: 'j', k: 'k', l: 'l', m: 'm', n: 'n', | ||
o: 'o', p: 'p', q: 'q', r: 'r', s: 's', t: 't', u: 'u', | ||
v: 'v', w: 'w', x: 'x', y: 'y', z: 'z', | ||
// Latin | ||
'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', 'Å': 'A', 'Æ': 'AE', | ||
'Ç': 'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I', | ||
'Î': 'I', 'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O', | ||
'Õ': 'O', 'Ö': 'O', 'Ő': 'O', 'Ø': 'O', 'Ù': 'U', 'Ú': 'U', 'Û': 'U', | ||
'Ü': 'U', 'Ű': 'U', 'Ý': 'Y', 'Þ': 'TH', 'ß': 'ss', 'à':'a', 'á':'a', | ||
'â': 'a', 'ã': 'a', 'ä': 'a', 'å': 'a', 'æ': 'ae', 'ç': 'c', 'è': 'e', | ||
'é': 'e', 'ê': 'e', 'ë': 'e', 'ì': 'i', 'í': 'i', 'î': 'i', 'ï': 'i', | ||
'ð': 'd', 'ñ': 'n', 'ò': 'o', 'ó': 'o', 'ô': 'o', 'õ': 'o', 'ö': 'o', | ||
'ő': 'o', 'ø': 'o', 'ù': 'u', 'ú': 'u', 'û': 'u', 'ü': 'u', 'ű': 'u', | ||
'ý': 'y', 'þ': 'th', 'ÿ': 'y', 'ẞ': 'SS', | ||
À: 'A', Á: 'A', Â: 'A', Ã: 'A', Ä: 'A', Å: 'A', Æ: 'AE', | ||
Ç: 'C', È: 'E', É: 'E', Ê: 'E', Ë: 'E', Ì: 'I', Í: 'I', | ||
Î: 'I', Ï: 'I', Ð: 'D', Ñ: 'N', Ò: 'O', Ó: 'O', Ô: 'O', | ||
Õ: 'O', Ö: 'O', Ő: 'O', Ø: 'O', Ù: 'U', Ú: 'U', Û: 'U', | ||
Ü: 'U', Ű: 'U', Ý: 'Y', Þ: 'TH', ß: 'ss', à: 'a', á: 'a', | ||
â: 'a', ã: 'a', ä: 'a', å: 'a', æ: 'ae', ç: 'c', è: 'e', | ||
é: 'e', ê: 'e', ë: 'e', ì: 'i', í: 'i', î: 'i', ï: 'i', | ||
ð: 'd', ñ: 'n', ò: 'o', ó: 'o', ô: 'o', õ: 'o', ö: 'o', | ||
ő: 'o', ø: 'o', ù: 'u', ú: 'u', û: 'u', ü: 'u', ű: 'u', | ||
ý: 'y', þ: 'th', ÿ: 'y', ẞ: 'SS', | ||
// Greek | ||
'α':'a', 'β':'b', 'γ':'g', 'δ':'d', 'ε':'e', 'ζ':'z', 'η':'h', 'θ':'8', | ||
'ι':'i', 'κ':'k', 'λ':'l', 'μ':'m', 'ν':'n', 'ξ':'3', 'ο':'o', 'π':'p', | ||
'ρ':'r', 'σ':'s', 'τ':'t', 'υ':'y', 'φ':'f', 'χ':'x', 'ψ':'ps', 'ω':'w', | ||
'ά':'a', 'έ':'e', 'ί':'i', 'ό':'o', 'ύ':'y', 'ή':'h', 'ώ':'w', 'ς':'s', | ||
'ϊ':'i', 'ΰ':'y', 'ϋ':'y', 'ΐ':'i', | ||
'Α':'A', 'Β':'B', 'Γ':'G', 'Δ':'D', 'Ε':'E', 'Ζ':'Z', 'Η':'H', 'Θ':'8', | ||
'Ι':'I', 'Κ':'K', 'Λ':'L', 'Μ':'M', 'Ν':'N', 'Ξ':'3', 'Ο':'O', 'Π':'P', | ||
'Ρ':'R', 'Σ':'S', 'Τ':'T', 'Υ':'Y', 'Φ':'F', 'Χ':'X', 'Ψ':'PS', 'Ω':'W', | ||
'Ά':'A', 'Έ':'E', 'Ί':'I', 'Ό':'O', 'Ύ':'Y', 'Ή':'H', 'Ώ':'W', 'Ϊ':'I', | ||
'Ϋ':'Y', | ||
α: 'a', β: 'b', γ: 'g', δ: 'd', ε: 'e', ζ: 'z', η: 'h', θ: '8', | ||
ι: 'i', κ: 'k', λ: 'l', μ: 'm', ν: 'n', ξ: '3', ο: 'o', π: 'p', | ||
ρ: 'r', σ: 's', τ: 't', υ: 'y', φ: 'f', χ: 'x', ψ: 'ps', ω: 'w', | ||
ά: 'a', έ: 'e', ί: 'i', ό: 'o', ύ: 'y', ή: 'h', ώ: 'w', ς: 's', | ||
ϊ: 'i', ΰ: 'y', ϋ: 'y', ΐ: 'i', | ||
Α: 'A', Β: 'B', Γ: 'G', Δ: 'D', Ε: 'E', Ζ: 'Z', Η: 'H', Θ: '8', | ||
Ι: 'I', Κ: 'K', Λ: 'L', Μ: 'M', Ν: 'N', Ξ: '3', Ο: 'O', Π: 'P', | ||
Ρ: 'R', Σ: 'S', Τ: 'T', Υ: 'Y', Φ: 'F', Χ: 'X', Ψ: 'PS', Ω: 'W', | ||
Ά: 'A', Έ: 'E', Ί: 'I', Ό: 'O', Ύ: 'Y', Ή: 'H', Ώ: 'W', Ϊ: 'I', | ||
Ϋ: 'Y', | ||
// Turkish | ||
'ş':'s', 'Ş':'S', 'ı':'i', 'İ':'I', | ||
'ğ':'g', 'Ğ':'G', | ||
ş: 's', Ş: 'S', ı: 'i', İ: 'I', | ||
ğ: 'g', Ğ: 'G', | ||
// Russian | ||
'а':'a', 'б':'b', 'в':'v', 'г':'g', 'д':'d', 'е':'e', 'ё':'yo', 'ж':'zh', | ||
'з':'z', 'и':'i', 'й':'j', 'к':'k', 'л':'l', 'м':'m', 'н':'n', 'о':'o', | ||
'п':'p', 'р':'r', 'с':'s', 'т':'t', 'у':'u', 'ф':'f', 'х':'h', 'ц':'c', | ||
'ч':'ch', 'ш':'sh', 'щ':'sh', 'ъ':'u', 'ы':'y', 'ь':'', 'э':'e', 'ю':'yu', | ||
'я':'ya', | ||
'А':'A', 'Б':'B', 'В':'V', 'Г':'G', 'Д':'D', 'Е':'E', 'Ё':'Yo', 'Ж':'Zh', | ||
'З':'Z', 'И':'I', 'Й':'J', 'К':'K', 'Л':'L', 'М':'M', 'Н':'N', 'О':'O', | ||
'П':'P', 'Р':'R', 'С':'S', 'Т':'T', 'У':'U', 'Ф':'F', 'Х':'H', 'Ц':'C', | ||
'Ч':'Ch', 'Ш':'Sh', 'Щ':'Sh', 'Ъ':'U', 'Ы':'Y', 'Ь':'', 'Э':'E', 'Ю':'Yu', | ||
'Я':'Ya', | ||
а: 'a', б: 'b', в: 'v', г: 'g', д: 'd', е: 'e', ё: 'yo', ж: 'zh', | ||
з: 'z', и: 'i', й: 'j', к: 'k', л: 'l', м: 'm', н: 'n', о: 'o', | ||
п: 'p', р: 'r', с: 's', т: 't', у: 'u', ф: 'f', х: 'h', ц: 'c', | ||
ч: 'ch', ш: 'sh', щ: 'sh', ъ: 'u', ы: 'y', ь: '', э: 'e', ю: 'yu', | ||
я: 'ya', | ||
А: 'A', Б: 'B', В: 'V', Г: 'G', Д: 'D', Е: 'E', Ё: 'Yo', Ж: 'Zh', | ||
З: 'Z', И: 'I', Й: 'J', К: 'K', Л: 'L', М: 'M', Н: 'N', О: 'O', | ||
П: 'P', Р: 'R', С: 'S', Т: 'T', У: 'U', Ф: 'F', Х: 'H', Ц: 'C', | ||
Ч: 'Ch', Ш: 'Sh', Щ: 'Sh', Ъ: 'U', Ы: 'Y', Ь: '', Э: 'E', Ю: 'Yu', | ||
Я: 'Ya', | ||
// Ukranian | ||
'Є':'Ye', 'І':'I', 'Ї':'Yi', 'Ґ':'G', 'є':'ye', 'і':'i', 'ї':'yi', 'ґ':'g', | ||
Є: 'Ye', І: 'I', Ї: 'Yi', Ґ: 'G', є: 'ye', і: 'i', ї: 'yi', ґ: 'g', | ||
// Czech | ||
'č':'c', 'ď':'d', 'ě':'e', 'ň': 'n', 'ř':'r', 'š':'s', 'ť':'t', 'ů':'u', | ||
'ž':'z', 'Č':'C', 'Ď':'D', 'Ě':'E', 'Ň': 'N', 'Ř':'R', 'Š':'S', 'Ť':'T', | ||
'Ů':'U', 'Ž':'Z', | ||
č: 'c', ď: 'd', ě: 'e', ň: 'n', ř: 'r', š: 's', ť: 't', ů: 'u', | ||
ž: 'z', Č: 'C', Ď: 'D', Ě: 'E', Ň: 'N', Ř: 'R', Š: 'S', Ť: 'T', | ||
Ů: 'U', Ž: 'Z', | ||
// Slovak | ||
'ľ':'l', 'Ľ':'L', | ||
ľ: 'l', Ľ: 'L', | ||
// Polish | ||
'ą':'a', 'ć':'c', 'ę':'e', 'ł':'l', 'ń':'n', 'ś':'s', 'ź':'z', | ||
'ż':'z', 'Ą':'A', 'Ć':'C', 'Ę':'E', 'Ł':'L', 'Ń':'N', 'Ś':'S', | ||
'Ź':'Z', 'Ż':'Z', | ||
ą: 'a', ć: 'c', ę: 'e', ł: 'l', ń: 'n', ś: 's', ź: 'z', | ||
ż: 'z', Ą: 'A', Ć: 'C', Ę: 'E', Ł: 'L', Ń: 'N', Ś: 'S', | ||
Ź: 'Z', Ż: 'Z', | ||
// Latvian | ||
'ā':'a', 'ē':'e', 'ģ':'g', 'ī':'i', 'ķ':'k', 'ļ':'l', 'ņ':'n', | ||
'ū':'u', 'Ā':'A', 'Ē':'E', 'Ģ':'G', 'Ī':'I', | ||
'Ķ':'K', 'Ļ':'L', 'Ņ':'N', 'Ū':'U', | ||
ā: 'a', ē: 'e', ģ: 'g', ī: 'i', ķ: 'k', ļ: 'l', ņ: 'n', | ||
ū: 'u', Ā: 'A', Ē: 'E', Ģ: 'G', Ī: 'I', | ||
Ķ: 'K', Ļ: 'L', Ņ: 'N', Ū: 'U', | ||
// Lithuanian | ||
'ė':'e', 'į':'i', 'ų':'u', 'Ė': 'E', 'Į': 'I', 'Ų':'U', | ||
ė: 'e', į: 'i', ų: 'u', Ė: 'E', Į: 'I', Ų: 'U', | ||
// Romanian | ||
'ț':'t', 'Ț':'T', 'ţ':'t', 'Ţ':'T', 'ș':'s', 'Ș':'S', 'ă':'a', 'Ă':'A', | ||
ț: 't', Ț: 'T', ţ: 't', Ţ: 'T', ș: 's', Ș: 'S', ă: 'a', Ă: 'A', | ||
// Vietnamese | ||
'Ạ': 'A', 'Ả': 'A', 'Ầ': 'A', 'Ấ': 'A', 'Ậ': 'A', 'Ẩ': 'A', 'Ẫ': 'A', | ||
'Ằ': 'A', 'Ắ': 'A', 'Ặ': 'A', 'Ẳ': 'A', 'Ẵ': 'A', 'Ẹ': 'E', 'Ẻ': 'E', | ||
'Ẽ': 'E', 'Ề': 'E', 'Ế': 'E', 'Ệ': 'E', 'Ể': 'E', 'Ễ': 'E', 'Ị': 'I', | ||
'Ỉ': 'I', 'Ĩ': 'I', 'Ọ': 'O', 'Ỏ': 'O', 'Ồ': 'O', 'Ố': 'O', 'Ộ': 'O', | ||
'Ổ': 'O', 'Ỗ': 'O', 'Ơ': 'O', 'Ờ': 'O', 'Ớ': 'O', 'Ợ': 'O', 'Ở': 'O', | ||
'Ỡ': 'O', 'Ụ': 'U', 'Ủ': 'U', 'Ũ': 'U', 'Ư': 'U', 'Ừ': 'U', 'Ứ': 'U', | ||
'Ự': 'U', 'Ử': 'U', 'Ữ': 'U', 'Ỳ': 'Y', 'Ỵ': 'Y', 'Ỷ': 'Y', 'Ỹ': 'Y', | ||
'Đ': 'D', 'ạ': 'a', 'ả': 'a', 'ầ': 'a', 'ấ': 'a', 'ậ': 'a', 'ẩ': 'a', | ||
'ẫ': 'a', 'ằ': 'a', 'ắ': 'a', 'ặ': 'a', 'ẳ': 'a', 'ẵ': 'a', 'ẹ': 'e', | ||
'ẻ': 'e', 'ẽ': 'e', 'ề': 'e', 'ế': 'e', 'ệ': 'e', 'ể': 'e', 'ễ': 'e', | ||
'ị': 'i', 'ỉ': 'i', 'ĩ': 'i', 'ọ': 'o', 'ỏ': 'o', 'ồ': 'o', 'ố': 'o', | ||
'ộ': 'o', 'ổ': 'o', 'ỗ': 'o', 'ơ': 'o', 'ờ': 'o', 'ớ': 'o', 'ợ': 'o', | ||
'ở': 'o', 'ỡ': 'o', 'ụ': 'u', 'ủ': 'u', 'ũ': 'u', 'ư': 'u', 'ừ': 'u', | ||
'ứ': 'u', 'ự': 'u', 'ử': 'u', 'ữ': 'u', 'ỳ': 'y', 'ỵ': 'y', 'ỷ': 'y', | ||
'ỹ': 'y', 'đ': 'd', | ||
Ạ: 'A', Ả: 'A', Ầ: 'A', Ấ: 'A', Ậ: 'A', Ẩ: 'A', Ẫ: 'A', | ||
Ằ: 'A', Ắ: 'A', Ặ: 'A', Ẳ: 'A', Ẵ: 'A', Ẹ: 'E', Ẻ: 'E', | ||
Ẽ: 'E', Ề: 'E', Ế: 'E', Ệ: 'E', Ể: 'E', Ễ: 'E', Ị: 'I', | ||
Ỉ: 'I', Ĩ: 'I', Ọ: 'O', Ỏ: 'O', Ồ: 'O', Ố: 'O', Ộ: 'O', | ||
Ổ: 'O', Ỗ: 'O', Ơ: 'O', Ờ: 'O', Ớ: 'O', Ợ: 'O', Ở: 'O', | ||
Ỡ: 'O', Ụ: 'U', Ủ: 'U', Ũ: 'U', Ư: 'U', Ừ: 'U', Ứ: 'U', | ||
Ự: 'U', Ử: 'U', Ữ: 'U', Ỳ: 'Y', Ỵ: 'Y', Ỷ: 'Y', Ỹ: 'Y', | ||
Đ: 'D', ạ: 'a', ả: 'a', ầ: 'a', ấ: 'a', ậ: 'a', ẩ: 'a', | ||
ẫ: 'a', ằ: 'a', ắ: 'a', ặ: 'a', ẳ: 'a', ẵ: 'a', ẹ: 'e', | ||
ẻ: 'e', ẽ: 'e', ề: 'e', ế: 'e', ệ: 'e', ể: 'e', ễ: 'e', | ||
ị: 'i', ỉ: 'i', ĩ: 'i', ọ: 'o', ỏ: 'o', ồ: 'o', ố: 'o', | ||
ộ: 'o', ổ: 'o', ỗ: 'o', ơ: 'o', ờ: 'o', ớ: 'o', ợ: 'o', | ||
ở: 'o', ỡ: 'o', ụ: 'u', ủ: 'u', ũ: 'u', ư: 'u', ừ: 'u', | ||
ứ: 'u', ự: 'u', ử: 'u', ữ: 'u', ỳ: 'y', ỵ: 'y', ỷ: 'y', | ||
ỹ: 'y', đ: 'd', | ||
// Georgian | ||
'ა': 'a', 'ბ': 'b', 'გ': 'g', 'დ': 'd', 'ე': 'e', 'ვ': 'v', 'ზ': 'z', | ||
'თ': 't', 'ი': 'i', 'კ': 'k', 'ლ': 'l', 'მ': 'm', 'ნ': 'n', 'ო': 'o', | ||
'პ': 'p', 'ჟ': 'zh', 'რ': 'r', 'ს': 's', 'ტ': 't', 'უ': 'u', 'ფ': 'f', | ||
'ქ': 'q', 'ღ': 'gh', 'ყ': 'k', 'შ': 'sh', 'ჩ': 'ch', 'ც': 'ts', 'ძ': 'dz', | ||
'წ': 'ts', 'ჭ': 'ch', 'ხ': 'kh', 'ჯ': 'j', 'ჰ': 'h', | ||
ა: 'a', ბ: 'b', გ: 'g', დ: 'd', ე: 'e', ვ: 'v', ზ: 'z', | ||
თ: 't', ი: 'i', კ: 'k', ლ: 'l', მ: 'm', ნ: 'n', ო: 'o', | ||
პ: 'p', ჟ: 'zh', რ: 'r', ს: 's', ტ: 't', უ: 'u', ფ: 'f', | ||
ქ: 'q', ღ: 'gh', ყ: 'k', შ: 'sh', ჩ: 'ch', ც: 'ts', ძ: 'dz', | ||
წ: 'ts', ჭ: 'ch', ხ: 'kh', ჯ: 'j', ჰ: 'h', | ||
// Currency | ||
@@ -202,9 +202,9 @@ '€': 'euro', '₢': 'cruzeiro', '₣': 'french franc', '£': 'pound', | ||
'₯': 'drachma', '₰': 'penny', '₱': 'peso', '₲': 'guarani', '₳': 'austral', | ||
'₴': 'hryvnia', '₵': 'cedi', '¢': 'cent', '¥': 'yen', '元': 'yuan', | ||
'円': 'yen', '﷼': 'rial', '₠': 'ecu', '¤': 'currency', '฿': 'baht', | ||
'$': 'dollar', '₹': 'indian rupee', | ||
'₴': 'hryvnia', '₵': 'cedi', '¢': 'cent', '¥': 'yen', 元: 'yuan', | ||
円: 'yen', '﷼': 'rial', '₠': 'ecu', '¤': 'currency', '฿': 'baht', | ||
$: 'dollar', '₹': 'indian rupee', | ||
// Symbols | ||
'©':'(c)', 'œ': 'oe', 'Œ': 'OE', '∑': 'sum', '®': '(r)', '†': '+', | ||
'“': '"', '”': '"', '‘': '\'', '’': '\'', '∂': 'd', 'ƒ': 'f', '™': 'tm', | ||
'℠': 'sm', '…': '...', '˚': 'o', 'º': 'o', 'ª': 'a', '•': '*', | ||
'©': '(c)', œ: 'oe', Œ: 'OE', '∑': 'sum', '®': '(r)', '†': '+', | ||
'“': '"', '”': '"', '‘': '\'', '’': '\'', '∂': 'd', ƒ: 'f', '™': 'tm', | ||
'℠': 'sm', '…': '...', '˚': 'o', º: 'o', ª: 'a', '•': '*', | ||
'∆': 'delta', '∞': 'infinity', '♥': 'love', '&': 'and', '|': 'or', | ||
@@ -211,0 +211,0 @@ '<': 'less', '>': 'greater', |
{ | ||
"name": "larvitslugify", | ||
"description": "Slugify string to make them url safe and more", | ||
"version": "0.11.4", | ||
"version": "0.11.5", | ||
"homepage": "https://github.com/larvit/larvitslugify", | ||
@@ -28,6 +28,6 @@ "author": "Lilleman <lilleman@larvit.se>", | ||
"devDependencies": { | ||
"mocha": "^5.2.0", | ||
"mocha-eslint": "^4.1.0" | ||
"mocha": "6.1.4", | ||
"mocha-eslint": "5.0.0" | ||
}, | ||
"license": "ISC" | ||
} |
@@ -18,6 +18,6 @@ [](https://travis-ci.org/larvit/larvitslugify) | ||
```javascript | ||
const slug = require('larvitslugify'); | ||
const slug = require('larvitslugify'); | ||
slug('i ♥ unicode'); // > i-love-unicode | ||
slug('unicode ♥ is ☢'); // > unicode-love-is-radioactive | ||
slug('i ♥ unicode'); // > i-love-unicode | ||
slug('unicode ♥ is ☢'); // > unicode-love-is-radioactive | ||
@@ -29,5 +29,5 @@ // If you prefer something else then `-` as seperator | ||
slug.charmap['♥'] = 'freaking love' | ||
slug('I ♥ UNICODE')); // > I-freaking-love-UNICODE | ||
slug('I ♥ UNICODE')); // > I-freaking-love-UNICODE | ||
slug('i <3 unicode'); // > i-love-unicode | ||
slug('i <3 unicode'); // > i-love-unicode | ||
``` | ||
@@ -46,13 +46,13 @@ | ||
slug('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 | ||
'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) | ||
//'wordLimit': 5 // Limits the amount of words to this number (Currently not supported) | ||
}); | ||
``` |
'use strict'; | ||
const assert = require('assert'), | ||
slug = require(__dirname + '/../index.js'); | ||
const assert = require('assert'); | ||
const slug = require(__dirname + '/../index.js'); | ||
describe('slug', function () { | ||
it('should convert input to string', function (done) { | ||
assert.strictEqual(slug(1), '1'); | ||
assert.strictEqual(slug(567890), '567890'); | ||
assert.strictEqual(slug(1), '1'); | ||
assert.strictEqual(slug(567890), '567890'); | ||
done(); | ||
@@ -14,7 +14,7 @@ }); | ||
it('should replace whitespaces with replacement', function (done) { | ||
assert.strictEqual(slug('foo bar buz'), 'foo-bar-buz'); | ||
assert.strictEqual(slug('foo bar buz', {'whitespaceReplaceChar': '_'}), 'foo_bar_buz'); | ||
assert.strictEqual(slug('foo bar buz', '_'), 'foo_bar_buz'); | ||
assert.strictEqual(slug('foo bar buz', {'whitespaceReplaceChar': ''}), 'foobarbuz'); | ||
assert.strictEqual(slug('foo bar buz', ''), 'foobarbuz'); | ||
assert.strictEqual(slug('foo bar buz'), 'foo-bar-buz'); | ||
assert.strictEqual(slug('foo bar buz', {whitespaceReplaceChar: '_'}), 'foo_bar_buz'); | ||
assert.strictEqual(slug('foo bar buz', '_'), 'foo_bar_buz'); | ||
assert.strictEqual(slug('foo bar buz', {whitespaceReplaceChar: ''}), 'foobarbuz'); | ||
assert.strictEqual(slug('foo bar buz', ''), 'foobarbuz'); | ||
done(); | ||
@@ -24,4 +24,4 @@ }); | ||
it('should remove trailing space if any', function (done) { | ||
assert.strictEqual(slug(' foo bar baz '), 'foo-bar-baz'); | ||
assert.strictEqual(slug(' foo bar baz ', {'trim': false}), '-foo-bar-baz-'); | ||
assert.strictEqual(slug(' foo bar baz '), 'foo-bar-baz'); | ||
assert.strictEqual(slug(' foo bar baz ', {trim: false}), '-foo-bar-baz-'); | ||
done(); | ||
@@ -31,6 +31,6 @@ }); | ||
it('should trim leading / trailing separators', function (done) { | ||
const text = '--words go here--', | ||
expected = 'words-go-here'; | ||
const text = '--words go here--'; | ||
const expected = 'words-go-here'; | ||
assert.strictEqual(slug(text), expected); | ||
assert.strictEqual(slug(text), expected); | ||
done(); | ||
@@ -40,3 +40,3 @@ }); | ||
it('should remove trailing separator if any', function (done) { | ||
assert.strictEqual(slug(' foo bar baz-'), 'foo-bar-baz'); | ||
assert.strictEqual(slug(' foo bar baz-'), 'foo-bar-baz'); | ||
done(); | ||
@@ -46,5 +46,5 @@ }); | ||
it('should remove not allowed chars', function (done) { | ||
assert.strictEqual(slug('foo, bar baz'), 'foo-bar-baz'); | ||
assert.strictEqual(slug('foo- bar baz'), 'foo-bar-baz'); | ||
assert.strictEqual(slug('foo] bar baz'), 'foo-bar-baz'); | ||
assert.strictEqual(slug('foo, bar baz'), 'foo-bar-baz'); | ||
assert.strictEqual(slug('foo- bar baz'), 'foo-bar-baz'); | ||
assert.strictEqual(slug('foo] bar baz'), 'foo-bar-baz'); | ||
done(); | ||
@@ -54,11 +54,11 @@ }); | ||
it('should leave allowed custom chars', function (done) { | ||
const allowed = ['.', '_', '~', '/']; | ||
const allowed = ['.', '_', '~', '/']; | ||
for (let i = 0; allowed[i] !== undefined; i ++) { | ||
const charmap = {}; | ||
for (let i = 0; allowed[i] !== undefined; i++) { | ||
const charmap = {}; | ||
Object.assign(charmap, slug.charmap); | ||
charmap[allowed[i]] = allowed[i]; | ||
assert.strictEqual(slug('bar ' + allowed[i] + ' foo baz', {'charmap': charmap}), 'bar-' + allowed[i] + '-foo-baz'); | ||
assert.strictEqual(slug('bar ' + allowed[i] + ' foo baz'), 'bar-foo-baz'); | ||
assert.strictEqual(slug('bar ' + allowed[i] + ' foo baz', {charmap: charmap}), 'bar-' + allowed[i] + '-foo-baz'); | ||
assert.strictEqual(slug('bar ' + allowed[i] + ' foo baz'), 'bar-foo-baz'); | ||
} | ||
@@ -70,5 +70,5 @@ | ||
it('should remove multiple whitespaces', function (done) { | ||
assert.strictEqual(slug('foo bar baz'), 'foo-bar-baz'); | ||
assert.strictEqual(slug('foo bar baz'), 'foo-bar-baz'); | ||
assert.strictEqual(slug('foo bar baz', {'removeMultipleWhitespace': false}), 'foo--bar-baz'); | ||
assert.strictEqual(slug('foo bar baz'), 'foo-bar-baz'); | ||
assert.strictEqual(slug('foo bar baz'), 'foo-bar-baz'); | ||
assert.strictEqual(slug('foo bar baz', {removeMultipleWhitespace: false}), 'foo--bar-baz'); | ||
done(); | ||
@@ -78,17 +78,17 @@ }); | ||
it('should replace latin chars', function (done) { | ||
const charmap = { | ||
'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', | ||
'Å': 'A', 'Æ': 'AE', 'Ç': 'C', 'È': 'E', 'É': 'E', | ||
'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I', 'Î': 'I', | ||
'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', | ||
'Ô': 'O', 'Õ': 'O', 'Ö': 'O', 'Ő': 'O', 'Ø': 'O', | ||
'Ù': 'U', 'Ú': 'U', 'Û': 'U', 'Ü': 'U', 'Ű': 'U', | ||
'Ý': 'Y', 'Þ': 'TH', 'ß': 'ss', 'à': 'a', 'á': 'a', | ||
'â': 'a', 'ã': 'a', 'ä': 'a', 'å': 'a', 'æ': 'ae', | ||
'ç': 'c', 'è': 'e', 'é': 'e', 'ê': 'e', 'ë': 'e', | ||
'ì': 'i', 'í': 'i', 'î': 'i', 'ï': 'i', 'ð': 'd', | ||
'ñ': 'n', 'ò': 'o', 'ó': 'o', 'ô': 'o', 'õ': 'o', | ||
'ö': 'o', 'ő': 'o', 'ø': 'o', 'ù': 'u', 'ú': 'u', | ||
'û': 'u', 'ü': 'u', 'ű': 'u', 'ý': 'y', 'þ': 'th', | ||
'ÿ': 'y', 'ẞ': 'SS' | ||
const charmap = { | ||
À: 'A', Á: 'A', Â: 'A', Ã: 'A', Ä: 'A', | ||
Å: 'A', Æ: 'AE', Ç: 'C', È: 'E', É: 'E', | ||
Ê: 'E', Ë: 'E', Ì: 'I', Í: 'I', Î: 'I', | ||
Ï: 'I', Ð: 'D', Ñ: 'N', Ò: 'O', Ó: 'O', | ||
Ô: 'O', Õ: 'O', Ö: 'O', Ő: 'O', Ø: 'O', | ||
Ù: 'U', Ú: 'U', Û: 'U', Ü: 'U', Ű: 'U', | ||
Ý: 'Y', Þ: 'TH', ß: 'ss', à: 'a', á: 'a', | ||
â: 'a', ã: 'a', ä: 'a', å: 'a', æ: 'ae', | ||
ç: 'c', è: 'e', é: 'e', ê: 'e', ë: 'e', | ||
ì: 'i', í: 'i', î: 'i', ï: 'i', ð: 'd', | ||
ñ: 'n', ò: 'o', ó: 'o', ô: 'o', õ: 'o', | ||
ö: 'o', ő: 'o', ø: 'o', ù: 'u', ú: 'u', | ||
û: 'u', ü: 'u', ű: 'u', ý: 'y', þ: 'th', | ||
ÿ: 'y', ẞ: 'SS' | ||
}; | ||
@@ -104,17 +104,17 @@ | ||
it('should replace greek chars', function (done) { | ||
const charmap = { | ||
'α': 'a', 'β': 'b', 'γ': 'g', 'δ': 'd', 'ε': 'e', | ||
'ζ': 'z', 'η': 'h', 'θ': '8', 'ι': 'i', 'κ': 'k', | ||
'λ': 'l', 'μ': 'm', 'ν': 'n', 'ξ': '3', 'ο': 'o', | ||
'π': 'p', 'ρ': 'r', 'σ': 's', 'τ': 't', 'υ': 'y', | ||
'φ': 'f', 'χ': 'x', 'ψ': 'ps', 'ω': 'w', 'ά': 'a', | ||
'έ': 'e', 'ί': 'i', 'ό': 'o', 'ύ': 'y', 'ή': 'h', | ||
'ώ': 'w', 'ς': 's', 'ϊ': 'i', 'ΰ': 'y', 'ϋ': 'y', | ||
'ΐ': 'i', 'Α': 'A', 'Β': 'B', 'Γ': 'G', 'Δ': 'D', | ||
'Ε': 'E', 'Ζ': 'Z', 'Η': 'H', 'Θ': '8', 'Ι': 'I', | ||
'Κ': 'K', 'Λ': 'L', 'Μ': 'M', 'Ν': 'N', 'Ξ': '3', | ||
'Ο': 'O', 'Π': 'P', 'Ρ': 'R', 'Σ': 'S', 'Τ': 'T', | ||
'Υ': 'Y', 'Φ': 'F', 'Χ': 'X', 'Ψ': 'PS', 'Ω': 'W', | ||
'Ά': 'A', 'Έ': 'E', 'Ί': 'I', 'Ό': 'O', 'Ύ': 'Y', | ||
'Ή': 'H', 'Ώ': 'W', 'Ϊ': 'I', 'Ϋ': 'Y' | ||
const charmap = { | ||
α: 'a', β: 'b', γ: 'g', δ: 'd', ε: 'e', | ||
ζ: 'z', η: 'h', θ: '8', ι: 'i', κ: 'k', | ||
λ: 'l', μ: 'm', ν: 'n', ξ: '3', ο: 'o', | ||
π: 'p', ρ: 'r', σ: 's', τ: 't', υ: 'y', | ||
φ: 'f', χ: 'x', ψ: 'ps', ω: 'w', ά: 'a', | ||
έ: 'e', ί: 'i', ό: 'o', ύ: 'y', ή: 'h', | ||
ώ: 'w', ς: 's', ϊ: 'i', ΰ: 'y', ϋ: 'y', | ||
ΐ: 'i', Α: 'A', Β: 'B', Γ: 'G', Δ: 'D', | ||
Ε: 'E', Ζ: 'Z', Η: 'H', Θ: '8', Ι: 'I', | ||
Κ: 'K', Λ: 'L', Μ: 'M', Ν: 'N', Ξ: '3', | ||
Ο: 'O', Π: 'P', Ρ: 'R', Σ: 'S', Τ: 'T', | ||
Υ: 'Y', Φ: 'F', Χ: 'X', Ψ: 'PS', Ω: 'W', | ||
Ά: 'A', Έ: 'E', Ί: 'I', Ό: 'O', Ύ: 'Y', | ||
Ή: 'H', Ώ: 'W', Ϊ: 'I', Ϋ: 'Y' | ||
}; | ||
@@ -130,6 +130,6 @@ | ||
it('should replace turkish chars', function (done) { | ||
const charmap = { | ||
'ş': 's', 'Ş': 'S', 'ı': 'i', 'İ': 'I', 'ç': 'c', | ||
'Ç': 'C', 'ü': 'u', 'Ü': 'U', 'ö': 'o', 'Ö': 'O', | ||
'ğ': 'g', 'Ğ': 'G' | ||
const charmap = { | ||
ş: 's', Ş: 'S', ı: 'i', İ: 'I', ç: 'c', | ||
Ç: 'C', ü: 'u', Ü: 'U', ö: 'o', Ö: 'O', | ||
ğ: 'g', Ğ: 'G' | ||
}; | ||
@@ -145,13 +145,13 @@ | ||
it('should replace cyrillic chars', function (done) { | ||
const charmap = { | ||
'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd', 'е': 'e', 'ё': 'yo', 'ж': 'zh', | ||
'з': 'z', 'и': 'i', 'й': 'j', 'к': 'k', 'л': 'l', 'м': 'm', 'н': 'n', 'о': 'o', | ||
'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u', 'ф': 'f', 'х': 'h', 'ц': 'c', | ||
'ч': 'ch', 'ш': 'sh', 'щ': 'sh', 'ъ': 'u', 'ы': 'y', 'ь': '', 'э': 'e', 'ю': 'yu', | ||
'я': 'ya', 'А': 'A', 'Б': 'B', 'В': 'V', 'Г': 'G', 'Д': 'D', 'Е': 'E', 'Ё': 'Yo', | ||
'Ж': 'Zh', 'З': 'Z', 'И': 'I', 'Й': 'J', 'К': 'K', 'Л': 'L', 'М': 'M', 'Н': 'N', | ||
'О': 'O', 'П': 'P', 'Р': 'R', 'С': 'S', 'Т': 'T', 'У': 'U', 'Ф': 'F', 'Х': 'H', | ||
'Ц': 'C', 'Ч': 'Ch', 'Ш': 'Sh', 'Щ': 'Sh', 'Ъ': 'U', 'Ы': 'Y', 'Ь': '', 'Э': 'E', | ||
'Ю': 'Yu', 'Я': 'Ya', 'Є': 'Ye', 'І': 'I', 'Ї': 'Yi', 'Ґ': 'G', 'є': 'ye', 'і': 'i', | ||
'ї': 'yi', 'ґ': 'g' | ||
const charmap = { | ||
а: 'a', б: 'b', в: 'v', г: 'g', д: 'd', е: 'e', ё: 'yo', ж: 'zh', | ||
з: 'z', и: 'i', й: 'j', к: 'k', л: 'l', м: 'm', н: 'n', о: 'o', | ||
п: 'p', р: 'r', с: 's', т: 't', у: 'u', ф: 'f', х: 'h', ц: 'c', | ||
ч: 'ch', ш: 'sh', щ: 'sh', ъ: 'u', ы: 'y', ь: '', э: 'e', ю: 'yu', | ||
я: 'ya', А: 'A', Б: 'B', В: 'V', Г: 'G', Д: 'D', Е: 'E', Ё: 'Yo', | ||
Ж: 'Zh', З: 'Z', И: 'I', Й: 'J', К: 'K', Л: 'L', М: 'M', Н: 'N', | ||
О: 'O', П: 'P', Р: 'R', С: 'S', Т: 'T', У: 'U', Ф: 'F', Х: 'H', | ||
Ц: 'C', Ч: 'Ch', Ш: 'Sh', Щ: 'Sh', Ъ: 'U', Ы: 'Y', Ь: '', Э: 'E', | ||
Ю: 'Yu', Я: 'Ya', Є: 'Ye', І: 'I', Ї: 'Yi', Ґ: 'G', є: 'ye', і: 'i', | ||
ї: 'yi', ґ: 'g' | ||
}; | ||
@@ -167,7 +167,7 @@ | ||
it('should replace czech chars', function (done) { | ||
const charmap = { | ||
'č': 'c', 'ď': 'd', 'ě': 'e', 'ň': 'n', 'ř': 'r', | ||
'š': 's', 'ť': 't', 'ů': 'u', 'ž': 'z', 'Č': 'C', | ||
'Ď': 'D', 'Ě': 'E', 'Ň': 'N', 'Ř': 'R', 'Š': 'S', | ||
'Ť': 'T', 'Ů': 'U', 'Ž': 'Z' | ||
const charmap = { | ||
č: 'c', ď: 'd', ě: 'e', ň: 'n', ř: 'r', | ||
š: 's', ť: 't', ů: 'u', ž: 'z', Č: 'C', | ||
Ď: 'D', Ě: 'E', Ň: 'N', Ř: 'R', Š: 'S', | ||
Ť: 'T', Ů: 'U', Ž: 'Z' | ||
}; | ||
@@ -183,4 +183,4 @@ | ||
it('should replace slovakian chars', function (done) { | ||
const charmap = { | ||
'ľ':'l', 'Ľ':'L', | ||
const charmap = { | ||
ľ: 'l', Ľ: 'L' | ||
}; | ||
@@ -196,7 +196,7 @@ | ||
it('should replace polish chars', function (done) { | ||
const charmap = { | ||
'ą': 'a', 'ć': 'c', 'ę': 'e', 'ł': 'l', 'ń': 'n', | ||
'ó': 'o', 'ś': 's', 'ź': 'z', 'ż': 'z', 'Ą': 'A', | ||
'Ć': 'C', 'Ę': 'E', 'Ł': 'L', 'Ń': 'N', 'Ś': 'S', | ||
'Ź': 'Z', 'Ż': 'Z' | ||
const charmap = { | ||
ą: 'a', ć: 'c', ę: 'e', ł: 'l', ń: 'n', | ||
ó: 'o', ś: 's', ź: 'z', ż: 'z', Ą: 'A', | ||
Ć: 'C', Ę: 'E', Ł: 'L', Ń: 'N', Ś: 'S', | ||
Ź: 'Z', Ż: 'Z' | ||
}; | ||
@@ -212,8 +212,8 @@ | ||
it('should replace latvian chars', function (done) { | ||
const charmap = { | ||
'ā': 'a', 'č': 'c', 'ē': 'e', 'ģ': 'g', 'ī': 'i', | ||
'ķ': 'k', 'ļ': 'l', 'ņ': 'n', 'š': 's', 'ū': 'u', | ||
'ž': 'z', 'Ā': 'A', 'Č': 'C', 'Ē': 'E', 'Ģ': 'G', | ||
'Ī': 'I', 'Ķ': 'K', 'Ļ': 'L', 'Ņ': 'N', 'Š': 'S', | ||
'Ū': 'U', 'Ž': 'Z' | ||
const charmap = { | ||
ā: 'a', č: 'c', ē: 'e', ģ: 'g', ī: 'i', | ||
ķ: 'k', ļ: 'l', ņ: 'n', š: 's', ū: 'u', | ||
ž: 'z', Ā: 'A', Č: 'C', Ē: 'E', Ģ: 'G', | ||
Ī: 'I', Ķ: 'K', Ļ: 'L', Ņ: 'N', Š: 'S', | ||
Ū: 'U', Ž: 'Z' | ||
}; | ||
@@ -229,16 +229,16 @@ | ||
it('should replace vietnamese chars', function (done) { | ||
const charmap = { | ||
'Ạ': 'A', 'Ả': 'A', 'Ầ': 'A', 'Ấ': 'A', 'Ậ': 'A', 'Ẩ': 'A', 'Ẫ': 'A', 'Ằ': 'A', | ||
'Ắ': 'A', 'Ặ': 'A', 'Ẳ': 'A', 'Ẵ': 'A', 'Ẹ': 'E', 'Ẻ': 'E', 'Ẽ': 'E', 'Ề': 'E', | ||
'Ế': 'E', 'Ệ': 'E', 'Ể': 'E', 'Ễ': 'E', 'Ị': 'I', 'Ỉ': 'I', 'Ĩ': 'I', 'Ọ': 'O', | ||
'Ỏ': 'O', 'Ồ': 'O', 'Ố': 'O', 'Ộ': 'O', 'Ổ': 'O', 'Ỗ': 'O', 'Ơ': 'O', 'Ờ': 'O', | ||
'Ớ': 'O', 'Ợ': 'O', 'Ở': 'O', 'Ỡ': 'O', 'Ụ': 'U', 'Ủ': 'U', 'Ũ': 'U', 'Ư': 'U', | ||
'Ừ': 'U', 'Ứ': 'U', 'Ự': 'U', 'Ử': 'U', 'Ữ': 'U', 'Ỳ': 'Y', 'Ỵ': 'Y', 'Ỷ': 'Y', | ||
'Ỹ': 'Y', 'Đ': 'D', 'ạ': 'a', 'ả': 'a', 'ầ': 'a', 'ấ': 'a', 'ậ': 'a', 'ẩ': 'a', | ||
'ẫ': 'a', 'ằ': 'a', 'ắ': 'a', 'ặ': 'a', 'ẳ': 'a', 'ẵ': 'a', 'ẹ': 'e', 'ẻ': 'e', | ||
'ẽ': 'e', 'ề': 'e', 'ế': 'e', 'ệ': 'e', 'ể': 'e', 'ễ': 'e', 'ị': 'i', 'ỉ': 'i', | ||
'ĩ': 'i', 'ọ': 'o', 'ỏ': 'o', 'ồ': 'o', 'ố': 'o', 'ộ': 'o', 'ổ': 'o', 'ỗ': 'o', | ||
'ơ': 'o', 'ờ': 'o', 'ớ': 'o', 'ợ': 'o', 'ở': 'o', 'ỡ': 'o', 'ụ': 'u', 'ủ': 'u', | ||
'ũ': 'u', 'ư': 'u', 'ừ': 'u', 'ứ': 'u', 'ự': 'u', 'ử': 'u', 'ữ': 'u', 'ỳ': 'y', | ||
'ỵ': 'y', 'ỷ': 'y', 'ỹ': 'y', 'đ': 'd' | ||
const charmap = { | ||
Ạ: 'A', Ả: 'A', Ầ: 'A', Ấ: 'A', Ậ: 'A', Ẩ: 'A', Ẫ: 'A', Ằ: 'A', | ||
Ắ: 'A', Ặ: 'A', Ẳ: 'A', Ẵ: 'A', Ẹ: 'E', Ẻ: 'E', Ẽ: 'E', Ề: 'E', | ||
Ế: 'E', Ệ: 'E', Ể: 'E', Ễ: 'E', Ị: 'I', Ỉ: 'I', Ĩ: 'I', Ọ: 'O', | ||
Ỏ: 'O', Ồ: 'O', Ố: 'O', Ộ: 'O', Ổ: 'O', Ỗ: 'O', Ơ: 'O', Ờ: 'O', | ||
Ớ: 'O', Ợ: 'O', Ở: 'O', Ỡ: 'O', Ụ: 'U', Ủ: 'U', Ũ: 'U', Ư: 'U', | ||
Ừ: 'U', Ứ: 'U', Ự: 'U', Ử: 'U', Ữ: 'U', Ỳ: 'Y', Ỵ: 'Y', Ỷ: 'Y', | ||
Ỹ: 'Y', Đ: 'D', ạ: 'a', ả: 'a', ầ: 'a', ấ: 'a', ậ: 'a', ẩ: 'a', | ||
ẫ: 'a', ằ: 'a', ắ: 'a', ặ: 'a', ẳ: 'a', ẵ: 'a', ẹ: 'e', ẻ: 'e', | ||
ẽ: 'e', ề: 'e', ế: 'e', ệ: 'e', ể: 'e', ễ: 'e', ị: 'i', ỉ: 'i', | ||
ĩ: 'i', ọ: 'o', ỏ: 'o', ồ: 'o', ố: 'o', ộ: 'o', ổ: 'o', ỗ: 'o', | ||
ơ: 'o', ờ: 'o', ớ: 'o', ợ: 'o', ở: 'o', ỡ: 'o', ụ: 'u', ủ: 'u', | ||
ũ: 'u', ư: 'u', ừ: 'u', ứ: 'u', ự: 'u', ử: 'u', ữ: 'u', ỳ: 'y', | ||
ỵ: 'y', ỷ: 'y', ỹ: 'y', đ: 'd' | ||
}; | ||
@@ -254,8 +254,8 @@ | ||
it('should replace georgian chars', function (done) { | ||
const charmap = { | ||
'ა': 'a', 'ბ': 'b', 'გ': 'g', 'დ': 'd', 'ე': 'e', 'ვ': 'v', 'ზ': 'z', | ||
'თ': 't', 'ი': 'i', 'კ': 'k', 'ლ': 'l', 'მ': 'm', 'ნ': 'n', 'ო': 'o', | ||
'პ': 'p', 'ჟ': 'zh', 'რ': 'r', 'ს': 's', 'ტ': 't', 'უ': 'u', 'ფ': 'f', | ||
'ქ': 'q', 'ღ': 'gh', 'ყ': 'k', 'შ': 'sh', 'ჩ': 'ch', 'ც': 'ts', 'ძ': 'dz', | ||
'წ': 'ts', 'ჭ': 'ch', 'ხ': 'kh', 'ჯ': 'j', 'ჰ': 'h', | ||
const charmap = { | ||
ა: 'a', ბ: 'b', გ: 'g', დ: 'd', ე: 'e', ვ: 'v', ზ: 'z', | ||
თ: 't', ი: 'i', კ: 'k', ლ: 'l', მ: 'm', ნ: 'n', ო: 'o', | ||
პ: 'p', ჟ: 'zh', რ: 'r', ს: 's', ტ: 't', უ: 'u', ფ: 'f', | ||
ქ: 'q', ღ: 'gh', ყ: 'k', შ: 'sh', ჩ: 'ch', ც: 'ts', ძ: 'dz', | ||
წ: 'ts', ჭ: 'ch', ხ: 'kh', ჯ: 'j', ჰ: 'h' | ||
}; | ||
@@ -271,3 +271,3 @@ | ||
it('should replace currencies', function (done) { | ||
const charmap = { | ||
const charmap = { | ||
'€': 'euro', | ||
@@ -297,4 +297,4 @@ '₢': 'cruzeiro', | ||
'¥': 'yen', | ||
'元': 'yuan', | ||
'円': 'yen', | ||
元: 'yuan', | ||
円: 'yen', | ||
'﷼': 'rial', | ||
@@ -304,3 +304,3 @@ '₠': 'ecu', | ||
'฿': 'baht', | ||
'$': 'dollar' | ||
$: 'dollar' | ||
}; | ||
@@ -316,10 +316,10 @@ | ||
it('should replace symbols', function (done) { | ||
const charmap = { | ||
const charmap = { | ||
'©': '(c)', | ||
'œ': 'oe', | ||
'Œ': 'OE', | ||
œ: 'oe', | ||
Œ: 'OE', | ||
'∑': 'sum', | ||
'®': '(r)', | ||
'∂': 'd', | ||
'ƒ': 'f', | ||
ƒ: 'f', | ||
'™': 'tm', | ||
@@ -329,4 +329,4 @@ '℠': 'sm', | ||
'˚': 'o', | ||
'º': 'o', | ||
'ª': 'a', | ||
º: 'o', | ||
ª: 'a', | ||
'∆': 'delta', | ||
@@ -349,6 +349,6 @@ '∞': 'infinity', | ||
it('should strip some symbols not in charmap', function (done) { | ||
const charmap = ['ħ', 'ĸ']; | ||
const charmap = ['ħ', 'ĸ']; | ||
for (let i = 0; charmap[i] !== undefined; i ++) { | ||
const char = charmap[i]; | ||
for (let i = 0; charmap[i] !== undefined; i++) { | ||
const char = charmap[i]; | ||
@@ -362,3 +362,3 @@ assert.strictEqual(slug('foo ' + char + ' bar baz'), 'foo-bar-baz'); | ||
it('should replace unicode', function (done) { | ||
const charmap = { | ||
const charmap = { | ||
'☢': 'radioactive', | ||
@@ -391,12 +391,12 @@ '☠': 'skull-and-bones', | ||
it('should allow altering the charmap', function (done) { | ||
const charmap = { | ||
'f': 'ph', | ||
'o': '0', | ||
'b': '8', | ||
'a': '4', | ||
'r': '2', | ||
'z': '5' | ||
const charmap = { | ||
f: 'ph', | ||
o: '0', | ||
b: '8', | ||
a: '4', | ||
r: '2', | ||
z: '5' | ||
}; | ||
assert.strictEqual(slug('foo bar baz', {'charmap': charmap}), 'ph00-842-845'); | ||
assert.strictEqual(slug('foo bar baz', {charmap: charmap}), 'ph00-842-845'); | ||
done(); | ||
@@ -416,4 +416,4 @@ }); | ||
it('should be flavourable', function (done) { | ||
const text = 'It\'s your journey ... we guide you through.', | ||
expected = 'Its-your-journey-we-guide-you-through'; | ||
const text = 'It\'s your journey ... we guide you through.'; | ||
const expected = 'Its-your-journey-we-guide-you-through'; | ||
@@ -424,17 +424,6 @@ assert.strictEqual(slug(text), expected); | ||
/*it('should allow to limit slug words (5, i.e.)', function (done) { | ||
var expected, text; | ||
text = 'It\'s Your Journey We Guide You Through.'; | ||
expected = 'Its-Your-Journey-We-Guide'; | ||
return [ | ||
slug(text, { | ||
wordLimit: 5 | ||
}) | ||
].should.eql([expected]); | ||
});*/ | ||
it('should save some character', function (done) { | ||
const text = 'It\'s Your Jöurney We Guide You Through.', | ||
expected = 'Its-Your-Jöurney-We-Guide-You-Through', | ||
charmap = {}; | ||
const text = 'It\'s Your Jöurney We Guide You Through.'; | ||
const expected = 'Its-Your-Jöurney-We-Guide-You-Through'; | ||
const charmap = {}; | ||
@@ -447,3 +436,3 @@ // Load in default charmap | ||
assert.strictEqual(slug(text, {'charmap': charmap}), expected); | ||
assert.strictEqual(slug(text, {charmap: charmap}), expected); | ||
done(); | ||
@@ -453,6 +442,6 @@ }); | ||
it('should save some character method 2', function (done) { | ||
const text = 'It\'s Your Jöurney We Guide You Through!', | ||
expected = 'Its-Your-Jöurney-We-Guide-You-Through'; | ||
const text = 'It\'s Your Jöurney We Guide You Through!'; | ||
const expected = 'Its-Your-Jöurney-We-Guide-You-Through'; | ||
assert.strictEqual(slug(text, {'save': 'ö'}), expected); | ||
assert.strictEqual(slug(text, {save: 'ö'}), expected); | ||
done(); | ||
@@ -462,6 +451,6 @@ }); | ||
it('should save some character method 2 multiple characters', function (done) { | ||
const text = 'It\'s Your Jöurney We Guide You Through!', | ||
expected = 'Its-Your-Jöurney-We-Guide-You-Through!'; | ||
const text = 'It\'s Your Jöurney We Guide You Through!'; | ||
const expected = 'Its-Your-Jöurney-We-Guide-You-Through!'; | ||
assert.strictEqual(slug(text, {'save': ['ö', '!']}), expected); | ||
assert.strictEqual(slug(text, {save: ['ö', '!']}), expected); | ||
done(); | ||
@@ -471,5 +460,5 @@ }); | ||
it('should save the dot character', function (done) { | ||
const text = 'It\'s Your Jöurney We Guide You Through.', | ||
expected = 'Its-Your-Journey-We-Guide-You-Through.', | ||
charmap = {}; | ||
const text = 'It\'s Your Jöurney We Guide You Through.'; | ||
const expected = 'Its-Your-Journey-We-Guide-You-Through.'; | ||
const charmap = {}; | ||
@@ -482,3 +471,3 @@ // Load in default charmap | ||
assert.strictEqual(slug(text, {'charmap': charmap}), expected); | ||
assert.strictEqual(slug(text, {charmap: charmap}), expected); | ||
done(); | ||
@@ -488,5 +477,5 @@ }); | ||
it('should save some characters', function (done) { | ||
const text = 'It\'s Your/Journey We Guide You Through €.', | ||
expected = 'Its-Your/Journey-We-Guide-You-Through-€', | ||
charmap = {}; | ||
const text = 'It\'s Your/Journey We Guide You Through €.'; | ||
const expected = 'Its-Your/Journey-We-Guide-You-Through-€'; | ||
const charmap = {}; | ||
@@ -500,3 +489,3 @@ // Load in default charmap | ||
assert.strictEqual(slug(text, {'charmap': charmap}), expected); | ||
assert.strictEqual(slug(text, {charmap: charmap}), expected); | ||
done(); | ||
@@ -506,4 +495,4 @@ }); | ||
return it('should not crash when sending invalid input, but instead return false', function (done) { | ||
const text = null, | ||
expected = 'null'; | ||
const text = null; | ||
const expected = 'null'; | ||
@@ -510,0 +499,0 @@ assert.strictEqual(slug(text), expected); |
'use strict'; | ||
require( | ||
'mocha-eslint')([__dirname + '/..'], | ||
require('mocha-eslint')( | ||
[__dirname + '/..'], | ||
{ | ||
// Increase the timeout of the test if linting takes to long | ||
'timeout': 5000, // Defaults to the global mocha `timeout` option | ||
timeout: 5000, // Defaults to the global mocha `timeout` option | ||
// Increase the time until a test is marked as slow | ||
'slow': 1000, // Defaults to the global mocha `slow` option | ||
slow: 1000 // Defaults to the global mocha `slow` option | ||
} | ||
); |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
30654
9
0
606