UNPKG

6.13 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../src/util/intlPatches.js"],"names":["intlFormats","USD","symbol","decimal","groupDelim","GBP","EUR","IntlPatches","formatToPartsPatch","currency","maximumFractionDigits","useGrouping","num","format","parts","type","value","integer","fraction","toFixed","match","intParts","firstGroupLength","length","integerSlice","push","JSON","stringify","slice","groups","map","intPart","groupDelimJSON","intAndGroupParts","parse","join","concat","toParts","formatToParts","resolvedOptions"],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;AAiBA,MAAMA,WAAW,GAAG;AAChBC,EAAAA,GAAG,EAAE;AACDC,IAAAA,MAAM,EAAE,GADP;AAEDC,IAAAA,OAAO,EAAE,GAFR;AAGDC,IAAAA,UAAU,EAAE;AAHX,GADW;AAMhBC,EAAAA,GAAG,EAAE;AACDH,IAAAA,MAAM,EAAE,GADP;AAEDC,IAAAA,OAAO,EAAE,GAFR;AAGDC,IAAAA,UAAU,EAAE;AAHX,GANW;AAWhBE,EAAAA,GAAG,EAAE;AACDJ,IAAAA,MAAM,EAAE,GADP;AAEDC,IAAAA,OAAO,EAAE,GAFR;AAGDC,IAAAA,UAAU,EAAE;AAHX;AAXW,CAApB;AAkBA,MAAMG,WAAW,GAAG;AAChBC,EAAAA,kBAAkB,CAAC;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,qBAAZ;AAAmCC,IAAAA;AAAnC,GAAD,EAAmDC,GAAnD,EAAwD;AACtE,UAAMC,MAAM,GAAGb,WAAW,CAACS,QAAD,CAAX,sBACRT,WAAW,CAACC,GADJ;AAEXC,MAAAA,MAAM,EAAEO;AAFG,MAAf;;AAIA,UAAM;AAAEP,MAAAA,MAAF;AAAUC,MAAAA,OAAV;AAAmBC,MAAAA;AAAnB,QAAkCS,MAAxC;AACA,UAAMC,KAAK,GAAG,CAAC;AAAEC,MAAAA,IAAI,EAAE,UAAR;AAAoBC,MAAAA,KAAK,EAAEd;AAA3B,KAAD,CAAd;AAEA,UAAM,CAACe,OAAD,EAA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I,EAAE,SAAR;AAAmBC,QAAAA,KAAK,EAAEC;AAA1B,OAAX;AACH;;AACD,WAAOH,KAAK,CAACsB,MAAN,CAAa,CAChB;AAAErB,MAAAA,IAAI,EAAE,SAAR;AAAmBC,MAAAA,KAAK,EAAEb;AAA1B,KADgB,EAEhB;AAAEY,MAAAA,IAAI,EAAE,UAAR;AAAoBC,MAAAA,KAAK,EAAEE;AAA3B,KAFgB,CAAb,CAAP;AAIH,GA5De;;AA8DhBmB,EAAAA,OAAO,CAACzB,GAAD,EAAM;AACT,WAAO,KAAK0B,aAAL,GACD,KAAKA,aAAL,CAAmB1B,GAAnB,CADC,GAEDL,WAAW,CAACC,kBAAZ,CAA+B,KAAK+B,eAAL,EAA/B,EAAuD3B,GAAvD,CAFN;AAGH;;AAlEe,CAApB;AAoEA,eAAeL,WAAf","sourcesContent":["/**\n * A [ponyfill](https://github.com/sindresorhus/ponyfill) is an opt-in polyfill,\n * which replaces missing builtins on older or non-compliant platforms, but\n * without monkey-patching the native API.\n *\n * Many browsers do not yet support Intl.NumberFormat.prototype.formatToParts,\n * which is tracked here: https://github.com/tc39/proposal-intl-formatToParts\n *\n * The polyfill available in that repository covers many edge cases, but it's\n * more functionality than we need at this stage, it's not distributed over\n * NPM, and it's 18kb. The below\n * [ponyfill](https://github.com/sindresorhus/ponyfill) is not fully compliant,\n * but it'll do for now.\n *\n * TODO: Replace with a formally maintained, but small-enough, ponyfill.\n */\n\nconst intlFormats = {\n USD: {\n symbol: '$',\n decimal: '.',\n groupDelim: ','\n },\n GBP: {\n symbol: '£',\n decimal: '.',\n groupDelim: ','\n },\n EUR: {\n symbol: '€',\n decimal: '.',\n groupDelim: ','\n }\n};\n\nconst IntlPatches = {\n formatToPartsPatch({ currency, maximumFractionDigits, useGrouping }, num) {\n const format = intlFormats[currency] || {\n ...intlFormats.USD,\n symbol: currency\n };\n const { symbol, decimal, groupDelim } = format;\n const parts = [{ type: 'currency', value: symbol }];\n\n const [integer, fraction] = num\n .toFixed(maximumFractionDigits)\n .match(/\\d+/g);\n\n if (useGrouping !== false) {\n const intParts = [];\n const firstGroupLength = integer.length % 3;\n let integerSlice = integer;\n if (firstGroupLength > 0) {\n intParts.push(\n JSON.stringify({\n type: 'integer',\n value: integer.slice(0, firstGroupLength)\n })\n );\n integerSlice = integer.slice(firstGroupLength);\n }\n\n const groups = integerSlice.match(/\\d{3}/g);\n\n if (groups) {\n intParts.push(\n ...groups.map(intPart =>\n JSON.stringify({\n type: 'integer',\n value: intPart\n })\n )\n );\n }\n\n const groupDelimJSON =\n ',' +\n JSON.stringify({\n type: 'group',\n value: groupDelim\n }) +\n ',';\n\n const intAndGroupParts = JSON.parse(\n `[${intParts.join(groupDelimJSON)}]`\n );\n\n parts.push(...intAndGroupParts);\n } else {\n parts.push({ type: 'integer', value: integer });\n }\n return parts.concat([\n { type: 'decimal', value: decimal },\n { type: 'fraction', value: fraction }\n ]);\n },\n\n toParts(num) {\n return this.formatToParts\n ? this.formatToParts(num)\n : IntlPatches.formatToPartsPatch(this.resolvedOptions(), num);\n }\n};\nexport default IntlPatches;\n"],"file":"intlPatches.js"}
\No newline at end of file