case insensitive selector, remove diacritics from selector name

master
vampi 3 months ago
parent 34d6b99fe0
commit 95a1da95e2

@ -67,15 +67,29 @@ app.get('/listVoices', (req, res, next) => {
}
}
let selectorMap = {};
const removeDiacritics = s => s.normalize('NFD').replace(/\p{Diacritic}/gu, '');
const getSelector = (name, id, provider) => {
let nameClean = removeDiacritics(name.toLowerCase());
if(!(nameClean in selectorMap)) {
selectorMap[nameClean] = true;
return removeDiacritics(name);
}
let idClean = id.toLowerCase().normalize('NFD').replace(/\p{Diacritic}/gu, '');
if(!(idClean in selectorMap)) {
selectorMap[idClean] = true;
return id;
}
let providerClean = provider.toLowerCase().normalize('NFD').replace(/\p{Diacritic}/gu, '');
selectorMap[`${providerClean}|${idClean}`] = true;
return `${provider}|${id}`;
};
for(let v of ret) {
v.selector = (v.name in selectorMap) ? ((v.id in selectorMap) ? `${v.provider}|${v.id}` : v.id) : v.name;
selectorMap[v.selector] = true;
v.selector = getSelector(v.name, v.id, v.provider);
if(v.alternatives) {
v.alternatives[0].selector = v.selector;
for(let i = 1; i < v.alternatives.length; i++) {
let a = v.alternatives[i];
a.selector = (a.name in selectorMap) ? ((a.id in selectorMap) ? `${a.provider}|${a.id}` : a.id) : a.name;
selectorMap[a.selector] = true;
a.selector = getSelector(a.name, a.id, a.provider);
}
}
}

Loading…
Cancel
Save