Skip to content

Commit 3bfc9ad

Browse files
committed
Add Internationalization to sorting.
1 parent 977fc01 commit 3bfc9ad

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
- updated: `RESTBuilder.file(name, filetarget, [filename])` can contain `filename` instead of buffer
4141
- updated: `U.streamer(beg, [end], onItem(item, index), [skip], [stream])` added a new argument `stream` for flushing buffer
4242
- updated: `ErrorBuilder.addTransform(name, callback(isResponse))` by adding new argument `isresponse`
43+
- updated: `sorting` (framework + NoSQL embedded), now supports `internationalization`
4344

4445
- fixed: (IMPORTANT) long messages in WebSocket
4546
- fixed: (IMPORTANT) `controller` param in schemas

nosql.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const CLUSTER_UNLOCK_COUNTER = { TYPE: 'nosql-counter-unlock' };
6060
const FLAGS_READ = ['get'];
6161
const COUNTER_MMA = [0, 0];
6262
const NOSQL_STR_END = { '"': true, ',': true, '}': true };
63+
const COMPARER = Intl.Collator().compare;
6364

6465
Object.freeze(EMPTYARRAY);
6566

@@ -1168,8 +1169,8 @@ function nosqlsortvalue(a, b, sorter) {
11681169
if (type === 'number')
11691170
return sorter.asc ? a > b : a < b;
11701171
else if (type === 'string') {
1171-
a = (a.length > 5 ? a.substring(0, 5) : a).toLowerCase().removeDiacritics();
1172-
var c = a.localeCompare(b);
1172+
a = (a.length > 5 ? a.substring(0, 5) : a);
1173+
var c = COMPARER(a, b);
11731174
return sorter.asc ? c === 1 : c === -1;
11741175
} else if (a instanceof Date)
11751176
return sorter.asc ? a > b : a < b;

utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const Fs = require('fs');
3636
const Events = require('events');
3737
const Crypto = require('crypto');
3838
const CONCAT = [null, null];
39+
const COMPARER = Intl.Collator().compare;
3940

4041
if (!global.framework_utils)
4142
global.framework_utils = exports;
@@ -3130,7 +3131,7 @@ String.prototype.contains = function(value, mustAll) {
31303131
* @return {Number}
31313132
*/
31323133
String.prototype.localeCompare2 = function(value) {
3133-
return this.removeDiacritics().localeCompare(value.removeDiacritics());
3134+
return COMPARER(this, value);
31343135
};
31353136

31363137
/**
@@ -4377,7 +4378,7 @@ Array.prototype.quicksort = Array.prototype.orderBy = function(name, asc, maxlen
43774378

43784379
// String
43794380
if (type === 1) {
4380-
return va && vb ? (asc ? (va.length > maxlength ? va.substring(0, maxlength) : va).removeDiacritics().localeCompare((vb.length > maxlength ? vb.substring(0, maxlength) : vb).removeDiacritics()) : (vb.length > maxlength ? vb.substring(0, maxlength) : vb).removeDiacritics().localeCompare((va.length > maxlength ? va.substring(0, maxlength) : va).removeDiacritics())) : 0;
4381+
return va && vb ? (asc ? COMPARER(va.length > maxlength ? va.substring(0, maxlength) : va, vb.length > maxlength ? vb.substring(0, maxlength) : vb) : COMPARER(vb.length > maxlength ? vb.substring(0, maxlength) : vb, va.length > maxlength ? va.substring(0, maxlength) : va)) : 0;
43814382
} else if (type === 2) {
43824383
return va > vb ? (asc ? 1 : -1) : va < vb ? (asc ? -1 : 1) : 0;
43834384
} else if (type === 3) {

0 commit comments

Comments
 (0)