parameterize
Advanced tools
Comparing version 0.0.7 to 0.0.9
@@ -8,2 +8,3 @@ { | ||
"name": "parameterize", | ||
"license": "MIT", | ||
"description": "This repository adds node.js and npm support for parameterize which is originally used in Ruby on Rails. It replaces special characters in a string so that it may be used as part of a 'pretty' URL.", | ||
@@ -18,3 +19,3 @@ "tags": [ | ||
], | ||
"version": "0.0.7", | ||
"version": "0.0.9", | ||
"repository": { | ||
@@ -21,0 +22,0 @@ "type": "git", |
var LATIN_MAP = { | ||
'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', 'Å': 'A', 'Æ': 'AE', 'Ç': | ||
'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I', 'Î': 'I', | ||
'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O', 'Õ': 'O', 'Ö': | ||
'Ï': 'I', 'Ð': 'D', 'Đ': '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', 'ó': | ||
'ì': 'i', 'í': 'i', 'î': 'i', 'ï': 'i', 'ð': 'd', 'đ': 'd', 'ñ': 'n', 'ò': 'o', 'ó': | ||
'o', 'ô': 'o', 'õ': 'o', 'ö': 'o', 'ő': 'o', 'ø': 'o', 'ù': 'u', 'ú': 'u', | ||
@@ -51,3 +51,3 @@ 'û': 'u', 'ü': 'u', 'ű': 'u', 'ý': 'y', 'þ': 'th', 'ÿ': 'y' | ||
} | ||
var POLISH_MAP = { | ||
@@ -58,3 +58,3 @@ 'ą':'a', 'ć':'c', 'ę':'e', 'ł':'l', 'ń':'n', 'ó':'o', 'ś':'s', 'ź':'z', | ||
} | ||
var LATVIAN_MAP = { | ||
@@ -65,3 +65,3 @@ 'ā':'a', 'č':'c', 'ē':'e', 'ģ':'g', 'ī':'i', 'ķ':'k', 'ļ':'l', 'ņ':'n', | ||
} | ||
var ALL_DOWNCODE_MAPS=new Array() | ||
@@ -77,3 +77,3 @@ ALL_DOWNCODE_MAPS[0]=LATIN_MAP | ||
ALL_DOWNCODE_MAPS[8]=LATVIAN_MAP | ||
var Downcoder = new Object(); | ||
@@ -97,5 +97,4 @@ Downcoder.Initialize = function() | ||
} | ||
downcode= function( slug ) | ||
{ | ||
var downcode = function(slug){ | ||
Downcoder.Initialize() ; | ||
@@ -126,5 +125,6 @@ var downcoded ="" | ||
} | ||
module.exports = function(s, num_chars) { | ||
parameterize = function(s, num_chars, delimiter) { | ||
delimiter = delimiter || '-' | ||
// changes, e.g., "Petty theft" to "petty_theft" | ||
@@ -135,7 +135,17 @@ // remove all these words from the string before urlifying | ||
// if downcode doesn't hit, the char will be stripped here | ||
s = s.replace(/[^-\w\s]/g, ''); // remove unneeded chars | ||
s = s.replace(/[^-\w\s\u4E00-\u9FA5]/g, ''); // remove unneeded chars | ||
s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces | ||
s = s.replace(/[-\s]+/g, '-'); // convert spaces to hyphens | ||
s = s.replace(/[-\s]+/g, delimiter); // convert spaces to hyphens | ||
s = s.toLowerCase(); // convert to lowercase | ||
return s.substring(0, num_chars);// trim to first num_chars chars | ||
} | ||
} | ||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = parameterize; | ||
} else if (typeof define === 'function' && define.amd) { | ||
define('parameterize', [], function(require, exports, module) { | ||
return parameterize; | ||
}); | ||
} | ||
9205
4
134