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 603 forks source link

Breaking change in CLDR 38.0.0 - currency formatting #911

Closed PeterDeKok closed 3 years ago

PeterDeKok commented 3 years ago
Globalize('en_GB').formatCurrency(1234, 'EUR')
TypeError: Cannot read property 'test' of undefined

    at node_modules/globalize/dist/globalize/currency.js:236:35

Probably as a result of this issue: Unicode JIRA - CLDR #13838 Which has been implemented (as it seems) from CLDR v38.0.0

(At least the) en-GB numbers data of the CLDR data now contains a more complex regex pattern:

// cldr-numbers-modern: 
// main/en-GB/numbers/currencyFormats-numberSystem-latn/currencySpacing/beforeCurrency/currencyMatch
// main/en-GB/numbers/currencyFormats-numberSystem-latn/currencySpacing/afterCurrency/currencyMatch
"[[:^S:]&[:^Z:]]"

Relevant code for convenience:

// globalize/dist/globalize/currency.js:180
var regexp = {
    "[:digit:]": /\d/,
    "[:^S:]": regexpNotS
};
// globalize/dist/globalize/currency.js:229
var currencyMatch = regexp[ currencySpacing[ i ].currencyMatch ];
// globalize/dist/globalize/currency.js:236
currencyMatch = currencyMatch.test( symbol.charAt( i ? symbol.length - 1 : 0 ) );
b1tzer0 commented 3 years ago

en_US is having the same error.

rxaviers commented 3 years ago

Thanks for the info. Will accept PR. Anyone willing to contribute the fix? Thanks in advance.

rxaviers commented 3 years ago

Fixed in 1.7.0