cibernox / svelte-intl-precompile

I18n library for Svelte.js that analyzes your keys at build time for max performance and minimal footprint
https://svelte-intl-precompile.com
ISC License
274 stars 13 forks source link

Currency formatting #36

Closed eden-omb closed 2 years ago

eden-omb commented 2 years ago

I'm trying to parse a number with the currency formatter as demonstrated here but getting the following error:

proxy.js:19 Error: [precompile-intl-runtime] Unknown "currency" number format.

My code is as follows:

  $: {
    console.log('raw price:', price)
    if (price) {
      let _price = $number(price, { format: 'currency' })
      console.log('formatted price:', _price)
    }
  }

When I try to just do $number(price) instead it works out just fine.

cibernox commented 2 years ago

Sorry about that, the docs were wrong. currency is not one of the default formats, it's a custom one that can be added, but I've used in my apps for long that I forgot that's not built-in.

I'd updated the docs. Also, unless your app only ever uses one currency it's a bad idea to name your format "currency", it should be more specific. A common practice is to name your format as the three letter currency code of your supported currencies. The example now reflects that:

https://svelte-intl-precompile.com/en/docs/usage#formatting

I'm closing this as it was a documentation error. Let me know if I can be of further assistance