mapbox / locale-utils

0 stars 2 forks source link

Replace parseLocaleIntoCodes with Intl.Locale #10

Open 1ec5 opened 2 years ago

1ec5 commented 2 years ago

parseLocaleIntoCodes() is now redundant to Intl.Locale and its properties like language, which has been supported by Node.js since v12.0.0. Intl.getCanonicalNames() is also useful in some of the same use cases. We should deprecate or remove parseLocaleIntoCodes(), because it’s probably less robust than the ICU-backed methods built into ECMAScript.

1ec5 commented 2 years ago

locale-utils:

let locale = utils.parseLocaleIntoCodes("es-MX");
// {
//     locale: "es-MX",
//     language: "es",
//     script: undefined,
//     region: "MX"
// }

Intl:

let locale = new Intl.Locale("es-MX");
locale.toLocaleString(); // "es-MX"
locale.language; // "es"
locale.script; // undefined
locale.region; // "MX"