,
const prefLocales = {};
req.headers['accept-language']
?.split(',')
.map(el => {
const [name, quality] = el.split(';q=');
return [quality ? +quality : 1, name];
})
.sort(([a], [b]) => b - a)
.reduce((res, [quality, name]) => {
res[name] = quality;
return res;
}, prefLocales);
|