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AAqB,GAAG,qBAAqB;YAC/G,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;YACjD,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;YACvD,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;YACvD,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;SACG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;KACjD;;;;;","names":[],"sources":["src/components/util/format-number/sc-format-number.tsx"],"sourcesContent":["import { Component, Prop } from '@stencil/core';\nimport { maybeConvertAmount } from '../../../functions/currency';\n\n//TODO: Remove this when unit types are supported\ninterface NumberFormatOptionsWithUnit extends Intl.NumberFormatOptions {\n unit: string;\n unitDisplay: 'long' | 'short' | 'narrow';\n}\n\nconst UNIT_TYPES = {\n kg: 'kilogram',\n lb: 'pound',\n g: 'gram',\n oz: 'ounce',\n};\n\n@Component({\n tag: 'sc-format-number',\n shadow: false,\n})\nexport class ScFormatNumber {\n /** The number to format. */\n @Prop() value: number = 0;\n\n /** The locale to use when formatting the number. */\n @Prop({ mutable: true }) locale: string;\n\n /** The formatting style to use. */\n @Prop() type: 'currency' | 'decimal' | 'percent' | 'unit' = 'decimal';\n\n /** Turns off grouping separators. */\n @Prop({ attribute: 'no-grouping' }) noGrouping: boolean = false;\n\n /** The currency to use when formatting. Must be an ISO 4217 currency code such as `USD` or `EUR`. */\n @Prop() currency = 'USD';\n\n /** How to display the currency. */\n @Prop() currencyDisplay: 'symbol' | 'narrowSymbol' | 'code' | 'name' = 'symbol';\n\n /** The minimum number of integer digits to use. Possible values are 1 - 21. */\n @Prop() minimumIntegerDigits: number;\n\n /** The minimum number of fraction digits to use. Possible values are 0 - 20. */\n @Prop() minimumFractionDigits: number = null;\n\n /** The maximum number of fraction digits to use. Possible values are 0 - 20. */\n @Prop() maximumFractionDigits: number;\n\n /** The minimum number of significant digits to use. Possible values are 1 - 21. */\n @Prop() minimumSignificantDigits: number;\n\n /** The maximum number of significant digits to use,. Possible values are 1 - 21. */\n @Prop() maximumSignificantDigits: number;\n\n /** Should we convert */\n @Prop() noConvert: boolean;\n\n /** The unit to use when formatting. */\n @Prop() unit: string = 'lb';\n\n render() {\n if (isNaN(this.value)) {\n return '';\n }\n const lang = navigator.language || (navigator as any)?.browserLanguage || (navigator.languages || ['en'])[0];\n\n // maybe convert zero decimal currencies.\n const value = this.noConvert || this.type !== 'currency' ? this.value : maybeConvertAmount(this.value, this.currency.toUpperCase());\n\n // decide how many decimal places to use.\n const minimumFractionDigits = value % 1 == 0 ? 0 : 2;\n\n return new Intl.NumberFormat(this.locale || lang, {\n style: this.type,\n currency: this.currency.toUpperCase(),\n currencyDisplay: this.currencyDisplay,\n useGrouping: !this.noGrouping,\n minimumIntegerDigits: this.minimumIntegerDigits,\n minimumFractionDigits: this.minimumFractionDigits !== null ? this.minimumFractionDigits : minimumFractionDigits,\n maximumFractionDigits: this.maximumFractionDigits,\n minimumSignificantDigits: this.minimumSignificantDigits,\n maximumSignificantDigits: this.maximumSignificantDigits,\n unit: UNIT_TYPES[this.unit],\n } as NumberFormatOptionsWithUnit).format(value);\n }\n}\n"],"version":3}