normalize-for-search
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "normalize-for-search", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"main": "src/normalize.js", | ||
@@ -5,0 +5,0 @@ "ignore": [ |
{ | ||
"name": "normalize-for-search", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Un-accents and un-umlauts characters in a string. Also preliminary converts the string to lower case. We use it for autocomplete: both for the matched strings -- on the server side, when indexing; and for the strings the user types into a text input in the browser.", | ||
@@ -5,0 +5,0 @@ "main": "src/normalize.js", |
@@ -7,41 +7,4 @@ /* jshint bitwise: false, maxcomplexity: 100 */ | ||
var normalizeForSearch = function (s) { | ||
// Production steps of ECMA-262, Edition 5, 15.4.4.19 | ||
// Reference: http://es5.github.com/#x15.4.4.19 | ||
if (!Array.prototype.map) { | ||
Array.prototype.map = function (callback, thisArg) { | ||
var T, A, k, O, len, kValue, mappedValue; | ||
if ((this === null) || (typeof this === 'undefined')) { | ||
throw new TypeError(' this is null or not defined'); | ||
} | ||
O = Object(this); | ||
len = O.length >>> 0; | ||
if (typeof callback !== 'function') { | ||
throw new TypeError(callback + ' is not a function'); | ||
} | ||
if (thisArg) { | ||
T = thisArg; | ||
} | ||
A = new Array(len); | ||
k = 0; | ||
while (k < len) { | ||
if (k in O) { | ||
kValue = O[k]; | ||
mappedValue = callback.call(T, kValue, k, O); | ||
A[k] = mappedValue; | ||
} | ||
k = k + 1; | ||
} | ||
return A; | ||
}; | ||
} | ||
return Array.prototype.map.call(s.toLowerCase(), function (c) { | ||
function filter(c) { | ||
switch (c) { | ||
@@ -97,3 +60,10 @@ case 'ä': | ||
} | ||
}).join(''); | ||
} | ||
var normalized = '', i, l; | ||
s = s.toLowerCase(); | ||
for (i = 0, l = s.length; i < l; i = i + 1) { | ||
normalized = normalized + filter(s.charAt(i)); | ||
} | ||
return normalized; | ||
}; | ||
@@ -100,0 +70,0 @@ |
14698
117