@ljharb @theScottyJam
Although itβs more than a year ago, I would like to point out that a language-independent string comparison method that compares code point instead of code unit would be very useful β unlike code unit ((a, b) => (a > b) - (a < b)
), this is not a thing that can be done effortlessly:
/**
* Compare two strings by (full) Unicode code point order.
* @param {string} x
* @param {string} y
* @returns {number}
*/
function compareFullUnicode(x, y) {
const ix = x[Symbol.iterator]();
const iy = y[Symbol.iterator]();
for (;;) {
const nx = ix.next();
const ny = iy.next();
if (nx.done && ny.done) {
return 0;
}
const cx = nx.done ? -1 : nx.value.codePointAt(0);
const cy = ny.done ? -1 : ny.value.codePointAt(0);
const diff = cx - cy;
if (diff) {
return diff;
}
}
}