globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.8k stars 602 forks source link

Make the constructor case-insensitive #947

Open danielt998 opened 8 months ago

danielt998 commented 8 months ago

If I run the following:

console.log("Globalize curr with currencyFormatter, ja-jp:" + Globalize("ja-jp").currencyFormatter("BGN", {
        compact: "short"
      })(112310));

      console.log("Globalize curr with currencyFormatter, ja-JP:" + Globalize("ja-JP").currencyFormatter("BGN", {
        compact: "short"
      })(112310));

I get

Globalize curr with currencyFormatter, ja:BGN 112K
Globalize curr with currencyFormatter, ja:BGN 11万

the latter of which is correct. I think the constructor should automatically capitalise the locale code correctly as this feels like something that could catch a lot of people out (I might be happy to raise a PR myself)

danielt998 commented 8 months ago

Also I think it would be helpful to emit a warning when a locale passed in is invalid, this is such an easy thing to miss