-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
38 lines (31 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var groperty = require('groperty')
, defaultAlphabet = 'aāáǎàâãąbcćčçdďðeēéěèêëęėfgğhıiīíǐìîïįjklłmnńňñoōóǒòôpqrřsśšştťuųūúǔùůûüǖǘǚǜvwxyýzźżžþæœøõåäö';
function international ( propList, alphabet ) {
alphabet = alphabet || defaultAlphabet;
return function(a, b) {
var i = -1
, aIndex
, bIndex;
if ( propList ) {
a = groperty(a, propList);
b = groperty(b, propList);
}
a = String(a || '').toLowerCase();
b = String(b || '').toLowerCase();
do {
i++;
if (!a[i] && b[i]) return -1;
if (a[i] && !b[i]) return 1;
aIndex = alphabet.indexOf(a[i]);
bIndex = alphabet.indexOf(b[i]);
if (aIndex === -1 || bIndex === -1) {
if (a[i] < b[i]) return -1;
if (a[i] > b[i]) return 1;
}
} while (aIndex === bIndex && i < a.length && i < b.length);
return aIndex - bIndex;
};
}
if (typeof module === 'object' && module.hasOwnProperty('exports')) {
module.exports = international;
}