{"version":3,"names":["UNIT_TYPES","kg","lb","g","oz","ScFormatNumber","render","isNaN","this","value","lang","navigator","language","browserLanguage","languages","noConvert","type","maybeConvertAmount","currency","toUpperCase","minimumFractionDigits","Intl","NumberFormat","locale","style","currencyDisplay","useGrouping","noGrouping","minimumIntegerDigits","maximumFractionDigits","minimumSignificantDigits","maximumSignificantDigits","unit","format"],"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"],"mappings":"wEASA,MAAMA,EAAa,CACjBC,GAAI,WACJC,GAAI,QACJC,EAAG,OACHC,GAAI,S,MAOOC,EAAc,M,oCAED,E,gCAMoC,U,gBAGF,M,cAGvC,M,qBAGoD,S,+DAM/B,K,wJAejB,I,CAEvB,MAAAC,GACE,GAAIC,MAAMC,KAAKC,OAAQ,CACrB,MAAO,E,CAET,MAAMC,EAAOC,UAAUC,WAAaD,YAAiB,MAAjBA,iBAAS,SAATA,UAAmBE,mBAAoBF,UAAUG,WAAa,CAAC,OAAO,GAG1G,MAAML,EAAQD,KAAKO,WAAaP,KAAKQ,OAAS,WAAaR,KAAKC,MAAQQ,EAAmBT,KAAKC,MAAOD,KAAKU,SAASC,eAGrH,MAAMC,EAAwBX,EAAQ,GAAK,EAAI,EAAI,EAEnD,OAAO,IAAIY,KAAKC,aAAad,KAAKe,QAAUb,EAAM,CAChDc,MAAOhB,KAAKQ,KACZE,SAAUV,KAAKU,SAASC,cACxBM,gBAAiBjB,KAAKiB,gBACtBC,aAAclB,KAAKmB,WACnBC,qBAAsBpB,KAAKoB,qBAC3BR,sBAAuBZ,KAAKY,wBAA0B,KAAOZ,KAAKY,sBAAwBA,EAC1FS,sBAAuBrB,KAAKqB,sBAC5BC,yBAA0BtB,KAAKsB,yBAC/BC,yBAA0BvB,KAAKuB,yBAC/BC,KAAMhC,EAAWQ,KAAKwB,QACUC,OAAOxB,E","ignoreList":[]}