For a poor man\'s implementation of near-collation-correct sorting on the client side I need a JavaScript function that does efficient single character rep
I just wanted to post my solution using String#localeCompare
const base_chars = [
'1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'-', '_', ' '
];
const fix = str => str.normalize('NFKD').split('')
.map(c => base_chars.find(bc => bc.localeCompare(c, 'en', { sensitivity: 'base' })==0))
.join('');
const str = 'OÒ óëå-123';
console.log(`fix(${str}) = ${fix(str)}`);