3 ms·
While JavaScript (in browsers) has no way to normalize precomposed/decomposed strings, it has standard methods to correctly compare them: https://developer.mozi
by panzi 13y ago
While JavaScript (in browsers) has no way to normalize precomposed/decomposed strings, it has standard methods to correctly compare them:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
E.g.:
var decomp="noël";
var precomp="noël";
console.log(decomp.split(""));
console.log(precomp.split(""));
console.log(decomp.localeCompare(precomp));
Prints:
["n", "o", "e", "̈", "l"]
["n", "o", "ë", "l"]
0
Browser support for this varies, The Intl.Collator interface is currently only supported Chrome (maybe also in Opera? Idk).
Note: In Chrome when comparing (e.g. sorting) a lot of strings String.prototype.localeCompare is much slower than using a pre-composed Intl.Collator instance (because internally localeCompare creates a new collator for each call). Using Intl.Collator rediced startup time of my http://greattuneplayer.jit.su/ http://greattuneplayer.jit.su/ immensely. node.js currently has no support for Intl.*. It probably will be a compile time option for 0.12.