Skip to content

Commit 168a8d5

Browse files
committed
Added: String.localeCompare2()
1 parent 887e0ed commit 168a8d5

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- added: property `controller.robot`
1212
- added: property `controller.mobile`
1313
- added: support for default theme name, e.g. `=?/index` (the framework replaces `?` for `default-theme`)
14+
- added: String.localeCompare2(value) --> same as localeCompare() but this method works with diacritics
1415

1516
- updated: (IMPORTANT) controller.isSecure was renamed to controller.secured
1617
- updated: (IMPORTANT) req.isSecure was renamed to req.secured

test/test-utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ function prototypeString() {
205205

206206
str = '// Configuration\nname : total.js\nage : 29\n// comment1 : comment1\n# comment2 : comment2\ndebug : false';
207207
assert.ok(JSON.stringify(str.parseConfig({ comment3: 'comment3' })) === '{"comment3":"comment3","name":"total.js","age":"29","debug":"false"}', 'String.parseConfig()');
208+
209+
assert.ok('á'.localeCompare2('a') === 0, 'localeCompare2 - 1');
210+
assert.ok('á'.localeCompare2('b') === -1, 'localeCompare2 - 2');
211+
assert.ok('č'.localeCompare2('b') === 1, 'localeCompare2 - 3');
208212
}
209213

210214
function prototypeArray() {

utils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,6 +2835,15 @@ String.prototype.configuration = function(def) {
28352835
return this.parseConfig(def);
28362836
};
28372837

2838+
/**
2839+
* Same functionality as as String.localeCompare() but this method works with latin.
2840+
* @param {String} value
2841+
* @return {Number}
2842+
*/
2843+
String.prototype.localeCompare2 = function(value) {
2844+
return this.removeDiacritics().localeCompare(value.removeDiacritics())
2845+
};
2846+
28382847
/**
28392848
* Parse configuration from a string
28402849
* @param {Object} def

0 commit comments

Comments
 (0)