@formatjs/ecma376 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +20 -25
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,29 +1,24 @@
1
- var NUMBER = 10000;
2
- var ALL_ZEROS = /^0+$/;
1
+ const NUMBER = 1e4;
2
+ const ALL_ZEROS = /^0+$/;
3
3
  function partToPattern(part) {
4
- switch (part.type) {
5
- default:
6
- return part.value;
7
- case 'currency':
8
- case 'compact':
9
- return "\"".concat(part.value, "\"");
10
- case 'integer':
11
- if (ALL_ZEROS.test(part.value)) {
12
- return part.value
13
- .split('')
14
- .map(function (_, i, arr) { return (i === arr.length - 1 ? '0' : '#'); })
15
- .join('');
16
- }
17
- return '#';
18
- }
4
+ switch (part.type) {
5
+ default: return part.value;
6
+ case "currency":
7
+ case "compact": return `"${part.value}"`;
8
+ case "integer":
9
+ if (ALL_ZEROS.test(part.value)) {
10
+ return part.value.split("").map((_, i, arr) => i === arr.length - 1 ? "0" : "#").join("");
11
+ }
12
+ return "#";
13
+ }
19
14
  }
20
15
  export function generateNumFmtPattern(locales, opts) {
21
- var nf = new Intl.NumberFormat(locales, opts);
22
- var positivePattern = nf.formatToParts(NUMBER).reduce(function (pattern, part) {
23
- return pattern + partToPattern(part);
24
- }, '');
25
- var negativePattern = nf.formatToParts(-NUMBER).reduce(function (pattern, part) {
26
- return pattern + partToPattern(part);
27
- }, '');
28
- return positivePattern + ';' + negativePattern;
16
+ const nf = new Intl.NumberFormat(locales, opts);
17
+ const positivePattern = nf.formatToParts(NUMBER).reduce((pattern, part) => {
18
+ return pattern + partToPattern(part);
19
+ }, "");
20
+ const negativePattern = nf.formatToParts(-NUMBER).reduce((pattern, part) => {
21
+ return pattern + partToPattern(part);
22
+ }, "");
23
+ return positivePattern + ";" + negativePattern;
29
24
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formatjs/ecma376",
3
3
  "description": "generate ecma376 numFmt in different locales & currencies",
4
- "version": "0.4.1",
4
+ "version": "0.4.3",
5
5
  "license": "ISC",
6
6
  "author": "Long Ho <holevietlong@gmail.com>",
7
7
  "type": "module",