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

Literal quotes not removed from compact number/currency formats #917

Open jmaicher opened 3 years ago

jmaicher commented 3 years ago

Hey :wave:

As you can see in the following example, literal quotes are not fully removed from compact number/currency formats.

Globalize("de").formatNumber(1_000_000, { compact: "short" });
// => 1 Mio'.'

Globalize("de").formatCurrency(1_000_000, "EUR", { compact: "short" });
// => 1 Mio'.' €

This is a regression that was introduced in 1.5.0 with this commit 8b2a006.

What would be a good approach to fix this? Does it make sense to remove literal quotes specifically from the compact part, or do we need to take more parts into consideration? Literal quotes are already partially removed in stringToParts.

rxaviers commented 3 years ago

Hi,

Thanks for filing this issue. I agree it makes sense to remove the quotes from the compact part :+1:. If you can submit a PR, it will be much appreciated. Thanks

Globalize("de").formatNumberToParts(1_000_000, { compact: "short" });
// > [
//   { type: 'integer', value: '1' },
//   { type: 'literal', value: ' ' },
//   { type: 'compact', value: "Mio'.'" }
// ]