@internationalized/number 3.5.3-nightly.4624 → 3.5.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.
- package/dist/NumberFormatter.main.js +36 -36
- package/dist/NumberFormatter.mjs +36 -36
- package/dist/NumberFormatter.module.js +36 -36
- package/dist/NumberParser.main.js +43 -43
- package/dist/NumberParser.mjs +43 -43
- package/dist/NumberParser.module.js +43 -43
- package/package.json +2 -2
|
@@ -18,18 +18,18 @@ $parcel$export(module.exports, "NumberFormatter", () => $0c1d5654b62fc485$export
|
|
|
18
18
|
let $0c1d5654b62fc485$var$supportsSignDisplay = false;
|
|
19
19
|
try {
|
|
20
20
|
// @ts-ignore
|
|
21
|
-
$0c1d5654b62fc485$var$supportsSignDisplay = new Intl.NumberFormat(
|
|
22
|
-
signDisplay:
|
|
23
|
-
}).resolvedOptions().signDisplay ===
|
|
21
|
+
$0c1d5654b62fc485$var$supportsSignDisplay = new Intl.NumberFormat('de-DE', {
|
|
22
|
+
signDisplay: 'exceptZero'
|
|
23
|
+
}).resolvedOptions().signDisplay === 'exceptZero';
|
|
24
24
|
// eslint-disable-next-line no-empty
|
|
25
25
|
} catch (e) {}
|
|
26
26
|
let $0c1d5654b62fc485$var$supportsUnit = false;
|
|
27
27
|
try {
|
|
28
28
|
// @ts-ignore
|
|
29
|
-
$0c1d5654b62fc485$var$supportsUnit = new Intl.NumberFormat(
|
|
30
|
-
style:
|
|
31
|
-
unit:
|
|
32
|
-
}).resolvedOptions().style ===
|
|
29
|
+
$0c1d5654b62fc485$var$supportsUnit = new Intl.NumberFormat('de-DE', {
|
|
30
|
+
style: 'unit',
|
|
31
|
+
unit: 'degree'
|
|
32
|
+
}).resolvedOptions().style === 'unit';
|
|
33
33
|
// eslint-disable-next-line no-empty
|
|
34
34
|
} catch (e) {}
|
|
35
35
|
// Polyfill for units since Safari doesn't support them yet. See https://bugs.webkit.org/show_bug.cgi?id=215438.
|
|
@@ -39,20 +39,20 @@ const $0c1d5654b62fc485$var$UNITS = {
|
|
|
39
39
|
degree: {
|
|
40
40
|
narrow: {
|
|
41
41
|
default: "\xb0",
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
'ja-JP': " \u5EA6",
|
|
43
|
+
'zh-TW': "\u5EA6",
|
|
44
|
+
'sl-SI': " \xb0"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
class $0c1d5654b62fc485$export$cc77c4ff7e8673c5 {
|
|
49
49
|
/** Formats a number value as a string, according to the locale and options provided to the constructor. */ format(value) {
|
|
50
|
-
let res =
|
|
50
|
+
let res = '';
|
|
51
51
|
if (!$0c1d5654b62fc485$var$supportsSignDisplay && this.options.signDisplay != null) res = $0c1d5654b62fc485$export$711b50b3c525e0f2(this.numberFormatter, this.options.signDisplay, value);
|
|
52
52
|
else res = this.numberFormatter.format(value);
|
|
53
|
-
if (this.options.style ===
|
|
53
|
+
if (this.options.style === 'unit' && !$0c1d5654b62fc485$var$supportsUnit) {
|
|
54
54
|
var _UNITS_unit;
|
|
55
|
-
let { unit: unit, unitDisplay: unitDisplay =
|
|
55
|
+
let { unit: unit, unitDisplay: unitDisplay = 'short', locale: locale } = this.resolvedOptions();
|
|
56
56
|
if (!unit) return res;
|
|
57
57
|
let values = (_UNITS_unit = $0c1d5654b62fc485$var$UNITS[unit]) === null || _UNITS_unit === void 0 ? void 0 : _UNITS_unit[unitDisplay];
|
|
58
58
|
res += values[locale] || values.default;
|
|
@@ -66,32 +66,32 @@ class $0c1d5654b62fc485$export$cc77c4ff7e8673c5 {
|
|
|
66
66
|
}
|
|
67
67
|
/** Formats a number range as a string. */ formatRange(start, end) {
|
|
68
68
|
// @ts-ignore
|
|
69
|
-
if (typeof this.numberFormatter.formatRange ===
|
|
69
|
+
if (typeof this.numberFormatter.formatRange === 'function') // @ts-ignore
|
|
70
70
|
return this.numberFormatter.formatRange(start, end);
|
|
71
|
-
if (end < start) throw new RangeError(
|
|
71
|
+
if (end < start) throw new RangeError('End date must be >= start date');
|
|
72
72
|
// Very basic fallback for old browsers.
|
|
73
73
|
return `${this.format(start)} \u{2013} ${this.format(end)}`;
|
|
74
74
|
}
|
|
75
75
|
/** Formats a number range as an array of parts. */ formatRangeToParts(start, end) {
|
|
76
76
|
// @ts-ignore
|
|
77
|
-
if (typeof this.numberFormatter.formatRangeToParts ===
|
|
77
|
+
if (typeof this.numberFormatter.formatRangeToParts === 'function') // @ts-ignore
|
|
78
78
|
return this.numberFormatter.formatRangeToParts(start, end);
|
|
79
|
-
if (end < start) throw new RangeError(
|
|
79
|
+
if (end < start) throw new RangeError('End date must be >= start date');
|
|
80
80
|
let startParts = this.numberFormatter.formatToParts(start);
|
|
81
81
|
let endParts = this.numberFormatter.formatToParts(end);
|
|
82
82
|
return [
|
|
83
83
|
...startParts.map((p)=>({
|
|
84
84
|
...p,
|
|
85
|
-
source:
|
|
85
|
+
source: 'startRange'
|
|
86
86
|
})),
|
|
87
87
|
{
|
|
88
|
-
type:
|
|
88
|
+
type: 'literal',
|
|
89
89
|
value: " \u2013 ",
|
|
90
|
-
source:
|
|
90
|
+
source: 'shared'
|
|
91
91
|
},
|
|
92
92
|
...endParts.map((p)=>({
|
|
93
93
|
...p,
|
|
94
|
-
source:
|
|
94
|
+
source: 'endRange'
|
|
95
95
|
}))
|
|
96
96
|
];
|
|
97
97
|
}
|
|
@@ -101,9 +101,9 @@ class $0c1d5654b62fc485$export$cc77c4ff7e8673c5 {
|
|
|
101
101
|
...options,
|
|
102
102
|
signDisplay: this.options.signDisplay
|
|
103
103
|
};
|
|
104
|
-
if (!$0c1d5654b62fc485$var$supportsUnit && this.options.style ===
|
|
104
|
+
if (!$0c1d5654b62fc485$var$supportsUnit && this.options.style === 'unit') options = {
|
|
105
105
|
...options,
|
|
106
|
-
style:
|
|
106
|
+
style: 'unit',
|
|
107
107
|
unit: this.options.unit,
|
|
108
108
|
unitDisplay: this.options.unitDisplay
|
|
109
109
|
};
|
|
@@ -116,33 +116,33 @@ class $0c1d5654b62fc485$export$cc77c4ff7e8673c5 {
|
|
|
116
116
|
}
|
|
117
117
|
function $0c1d5654b62fc485$var$getCachedNumberFormatter(locale, options = {}) {
|
|
118
118
|
let { numberingSystem: numberingSystem } = options;
|
|
119
|
-
if (numberingSystem && locale.includes(
|
|
120
|
-
if (!locale.includes(
|
|
119
|
+
if (numberingSystem && locale.includes('-nu-')) {
|
|
120
|
+
if (!locale.includes('-u-')) locale += '-u-';
|
|
121
121
|
locale += `-nu-${numberingSystem}`;
|
|
122
122
|
}
|
|
123
|
-
if (options.style ===
|
|
123
|
+
if (options.style === 'unit' && !$0c1d5654b62fc485$var$supportsUnit) {
|
|
124
124
|
var _UNITS_unit;
|
|
125
|
-
let { unit: unit, unitDisplay: unitDisplay =
|
|
125
|
+
let { unit: unit, unitDisplay: unitDisplay = 'short' } = options;
|
|
126
126
|
if (!unit) throw new Error('unit option must be provided with style: "unit"');
|
|
127
127
|
if (!((_UNITS_unit = $0c1d5654b62fc485$var$UNITS[unit]) === null || _UNITS_unit === void 0 ? void 0 : _UNITS_unit[unitDisplay])) throw new Error(`Unsupported unit ${unit} with unitDisplay = ${unitDisplay}`);
|
|
128
128
|
options = {
|
|
129
129
|
...options,
|
|
130
|
-
style:
|
|
130
|
+
style: 'decimal'
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
|
-
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() :
|
|
133
|
+
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() : '');
|
|
134
134
|
if ($0c1d5654b62fc485$var$formatterCache.has(cacheKey)) return $0c1d5654b62fc485$var$formatterCache.get(cacheKey);
|
|
135
135
|
let numberFormatter = new Intl.NumberFormat(locale, options);
|
|
136
136
|
$0c1d5654b62fc485$var$formatterCache.set(cacheKey, numberFormatter);
|
|
137
137
|
return numberFormatter;
|
|
138
138
|
}
|
|
139
139
|
function $0c1d5654b62fc485$export$711b50b3c525e0f2(numberFormat, signDisplay, num) {
|
|
140
|
-
if (signDisplay ===
|
|
141
|
-
else if (signDisplay ===
|
|
140
|
+
if (signDisplay === 'auto') return numberFormat.format(num);
|
|
141
|
+
else if (signDisplay === 'never') return numberFormat.format(Math.abs(num));
|
|
142
142
|
else {
|
|
143
143
|
let needsPositiveSign = false;
|
|
144
|
-
if (signDisplay ===
|
|
145
|
-
else if (signDisplay ===
|
|
144
|
+
if (signDisplay === 'always') needsPositiveSign = num > 0 || Object.is(num, 0);
|
|
145
|
+
else if (signDisplay === 'exceptZero') {
|
|
146
146
|
if (Object.is(num, -0) || Object.is(num, 0)) num = Math.abs(num);
|
|
147
147
|
else needsPositiveSign = num > 0;
|
|
148
148
|
}
|
|
@@ -150,11 +150,11 @@ function $0c1d5654b62fc485$export$711b50b3c525e0f2(numberFormat, signDisplay, nu
|
|
|
150
150
|
let negative = numberFormat.format(-num);
|
|
151
151
|
let noSign = numberFormat.format(num);
|
|
152
152
|
// ignore RTL/LTR marker character
|
|
153
|
-
let minus = negative.replace(noSign,
|
|
153
|
+
let minus = negative.replace(noSign, '').replace(/\u200e|\u061C/, '');
|
|
154
154
|
if ([
|
|
155
155
|
...minus
|
|
156
|
-
].length !== 1) console.warn(
|
|
157
|
-
let positive = negative.replace(noSign,
|
|
156
|
+
].length !== 1) console.warn('@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case');
|
|
157
|
+
let positive = negative.replace(noSign, '!!!').replace(minus, '+').replace('!!!', noSign);
|
|
158
158
|
return positive;
|
|
159
159
|
} else return numberFormat.format(num);
|
|
160
160
|
}
|
package/dist/NumberFormatter.mjs
CHANGED
|
@@ -12,18 +12,18 @@
|
|
|
12
12
|
let $488c6ddbf4ef74c2$var$supportsSignDisplay = false;
|
|
13
13
|
try {
|
|
14
14
|
// @ts-ignore
|
|
15
|
-
$488c6ddbf4ef74c2$var$supportsSignDisplay = new Intl.NumberFormat(
|
|
16
|
-
signDisplay:
|
|
17
|
-
}).resolvedOptions().signDisplay ===
|
|
15
|
+
$488c6ddbf4ef74c2$var$supportsSignDisplay = new Intl.NumberFormat('de-DE', {
|
|
16
|
+
signDisplay: 'exceptZero'
|
|
17
|
+
}).resolvedOptions().signDisplay === 'exceptZero';
|
|
18
18
|
// eslint-disable-next-line no-empty
|
|
19
19
|
} catch (e) {}
|
|
20
20
|
let $488c6ddbf4ef74c2$var$supportsUnit = false;
|
|
21
21
|
try {
|
|
22
22
|
// @ts-ignore
|
|
23
|
-
$488c6ddbf4ef74c2$var$supportsUnit = new Intl.NumberFormat(
|
|
24
|
-
style:
|
|
25
|
-
unit:
|
|
26
|
-
}).resolvedOptions().style ===
|
|
23
|
+
$488c6ddbf4ef74c2$var$supportsUnit = new Intl.NumberFormat('de-DE', {
|
|
24
|
+
style: 'unit',
|
|
25
|
+
unit: 'degree'
|
|
26
|
+
}).resolvedOptions().style === 'unit';
|
|
27
27
|
// eslint-disable-next-line no-empty
|
|
28
28
|
} catch (e) {}
|
|
29
29
|
// Polyfill for units since Safari doesn't support them yet. See https://bugs.webkit.org/show_bug.cgi?id=215438.
|
|
@@ -33,20 +33,20 @@ const $488c6ddbf4ef74c2$var$UNITS = {
|
|
|
33
33
|
degree: {
|
|
34
34
|
narrow: {
|
|
35
35
|
default: "\xb0",
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
'ja-JP': " \u5EA6",
|
|
37
|
+
'zh-TW': "\u5EA6",
|
|
38
|
+
'sl-SI': " \xb0"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
class $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 {
|
|
43
43
|
/** Formats a number value as a string, according to the locale and options provided to the constructor. */ format(value) {
|
|
44
|
-
let res =
|
|
44
|
+
let res = '';
|
|
45
45
|
if (!$488c6ddbf4ef74c2$var$supportsSignDisplay && this.options.signDisplay != null) res = $488c6ddbf4ef74c2$export$711b50b3c525e0f2(this.numberFormatter, this.options.signDisplay, value);
|
|
46
46
|
else res = this.numberFormatter.format(value);
|
|
47
|
-
if (this.options.style ===
|
|
47
|
+
if (this.options.style === 'unit' && !$488c6ddbf4ef74c2$var$supportsUnit) {
|
|
48
48
|
var _UNITS_unit;
|
|
49
|
-
let { unit: unit, unitDisplay: unitDisplay =
|
|
49
|
+
let { unit: unit, unitDisplay: unitDisplay = 'short', locale: locale } = this.resolvedOptions();
|
|
50
50
|
if (!unit) return res;
|
|
51
51
|
let values = (_UNITS_unit = $488c6ddbf4ef74c2$var$UNITS[unit]) === null || _UNITS_unit === void 0 ? void 0 : _UNITS_unit[unitDisplay];
|
|
52
52
|
res += values[locale] || values.default;
|
|
@@ -60,32 +60,32 @@ class $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 {
|
|
|
60
60
|
}
|
|
61
61
|
/** Formats a number range as a string. */ formatRange(start, end) {
|
|
62
62
|
// @ts-ignore
|
|
63
|
-
if (typeof this.numberFormatter.formatRange ===
|
|
63
|
+
if (typeof this.numberFormatter.formatRange === 'function') // @ts-ignore
|
|
64
64
|
return this.numberFormatter.formatRange(start, end);
|
|
65
|
-
if (end < start) throw new RangeError(
|
|
65
|
+
if (end < start) throw new RangeError('End date must be >= start date');
|
|
66
66
|
// Very basic fallback for old browsers.
|
|
67
67
|
return `${this.format(start)} \u{2013} ${this.format(end)}`;
|
|
68
68
|
}
|
|
69
69
|
/** Formats a number range as an array of parts. */ formatRangeToParts(start, end) {
|
|
70
70
|
// @ts-ignore
|
|
71
|
-
if (typeof this.numberFormatter.formatRangeToParts ===
|
|
71
|
+
if (typeof this.numberFormatter.formatRangeToParts === 'function') // @ts-ignore
|
|
72
72
|
return this.numberFormatter.formatRangeToParts(start, end);
|
|
73
|
-
if (end < start) throw new RangeError(
|
|
73
|
+
if (end < start) throw new RangeError('End date must be >= start date');
|
|
74
74
|
let startParts = this.numberFormatter.formatToParts(start);
|
|
75
75
|
let endParts = this.numberFormatter.formatToParts(end);
|
|
76
76
|
return [
|
|
77
77
|
...startParts.map((p)=>({
|
|
78
78
|
...p,
|
|
79
|
-
source:
|
|
79
|
+
source: 'startRange'
|
|
80
80
|
})),
|
|
81
81
|
{
|
|
82
|
-
type:
|
|
82
|
+
type: 'literal',
|
|
83
83
|
value: " \u2013 ",
|
|
84
|
-
source:
|
|
84
|
+
source: 'shared'
|
|
85
85
|
},
|
|
86
86
|
...endParts.map((p)=>({
|
|
87
87
|
...p,
|
|
88
|
-
source:
|
|
88
|
+
source: 'endRange'
|
|
89
89
|
}))
|
|
90
90
|
];
|
|
91
91
|
}
|
|
@@ -95,9 +95,9 @@ class $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 {
|
|
|
95
95
|
...options,
|
|
96
96
|
signDisplay: this.options.signDisplay
|
|
97
97
|
};
|
|
98
|
-
if (!$488c6ddbf4ef74c2$var$supportsUnit && this.options.style ===
|
|
98
|
+
if (!$488c6ddbf4ef74c2$var$supportsUnit && this.options.style === 'unit') options = {
|
|
99
99
|
...options,
|
|
100
|
-
style:
|
|
100
|
+
style: 'unit',
|
|
101
101
|
unit: this.options.unit,
|
|
102
102
|
unitDisplay: this.options.unitDisplay
|
|
103
103
|
};
|
|
@@ -110,33 +110,33 @@ class $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 {
|
|
|
110
110
|
}
|
|
111
111
|
function $488c6ddbf4ef74c2$var$getCachedNumberFormatter(locale, options = {}) {
|
|
112
112
|
let { numberingSystem: numberingSystem } = options;
|
|
113
|
-
if (numberingSystem && locale.includes(
|
|
114
|
-
if (!locale.includes(
|
|
113
|
+
if (numberingSystem && locale.includes('-nu-')) {
|
|
114
|
+
if (!locale.includes('-u-')) locale += '-u-';
|
|
115
115
|
locale += `-nu-${numberingSystem}`;
|
|
116
116
|
}
|
|
117
|
-
if (options.style ===
|
|
117
|
+
if (options.style === 'unit' && !$488c6ddbf4ef74c2$var$supportsUnit) {
|
|
118
118
|
var _UNITS_unit;
|
|
119
|
-
let { unit: unit, unitDisplay: unitDisplay =
|
|
119
|
+
let { unit: unit, unitDisplay: unitDisplay = 'short' } = options;
|
|
120
120
|
if (!unit) throw new Error('unit option must be provided with style: "unit"');
|
|
121
121
|
if (!((_UNITS_unit = $488c6ddbf4ef74c2$var$UNITS[unit]) === null || _UNITS_unit === void 0 ? void 0 : _UNITS_unit[unitDisplay])) throw new Error(`Unsupported unit ${unit} with unitDisplay = ${unitDisplay}`);
|
|
122
122
|
options = {
|
|
123
123
|
...options,
|
|
124
|
-
style:
|
|
124
|
+
style: 'decimal'
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
|
-
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() :
|
|
127
|
+
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() : '');
|
|
128
128
|
if ($488c6ddbf4ef74c2$var$formatterCache.has(cacheKey)) return $488c6ddbf4ef74c2$var$formatterCache.get(cacheKey);
|
|
129
129
|
let numberFormatter = new Intl.NumberFormat(locale, options);
|
|
130
130
|
$488c6ddbf4ef74c2$var$formatterCache.set(cacheKey, numberFormatter);
|
|
131
131
|
return numberFormatter;
|
|
132
132
|
}
|
|
133
133
|
function $488c6ddbf4ef74c2$export$711b50b3c525e0f2(numberFormat, signDisplay, num) {
|
|
134
|
-
if (signDisplay ===
|
|
135
|
-
else if (signDisplay ===
|
|
134
|
+
if (signDisplay === 'auto') return numberFormat.format(num);
|
|
135
|
+
else if (signDisplay === 'never') return numberFormat.format(Math.abs(num));
|
|
136
136
|
else {
|
|
137
137
|
let needsPositiveSign = false;
|
|
138
|
-
if (signDisplay ===
|
|
139
|
-
else if (signDisplay ===
|
|
138
|
+
if (signDisplay === 'always') needsPositiveSign = num > 0 || Object.is(num, 0);
|
|
139
|
+
else if (signDisplay === 'exceptZero') {
|
|
140
140
|
if (Object.is(num, -0) || Object.is(num, 0)) num = Math.abs(num);
|
|
141
141
|
else needsPositiveSign = num > 0;
|
|
142
142
|
}
|
|
@@ -144,11 +144,11 @@ function $488c6ddbf4ef74c2$export$711b50b3c525e0f2(numberFormat, signDisplay, nu
|
|
|
144
144
|
let negative = numberFormat.format(-num);
|
|
145
145
|
let noSign = numberFormat.format(num);
|
|
146
146
|
// ignore RTL/LTR marker character
|
|
147
|
-
let minus = negative.replace(noSign,
|
|
147
|
+
let minus = negative.replace(noSign, '').replace(/\u200e|\u061C/, '');
|
|
148
148
|
if ([
|
|
149
149
|
...minus
|
|
150
|
-
].length !== 1) console.warn(
|
|
151
|
-
let positive = negative.replace(noSign,
|
|
150
|
+
].length !== 1) console.warn('@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case');
|
|
151
|
+
let positive = negative.replace(noSign, '!!!').replace(minus, '+').replace('!!!', noSign);
|
|
152
152
|
return positive;
|
|
153
153
|
} else return numberFormat.format(num);
|
|
154
154
|
}
|
|
@@ -12,18 +12,18 @@
|
|
|
12
12
|
let $488c6ddbf4ef74c2$var$supportsSignDisplay = false;
|
|
13
13
|
try {
|
|
14
14
|
// @ts-ignore
|
|
15
|
-
$488c6ddbf4ef74c2$var$supportsSignDisplay = new Intl.NumberFormat(
|
|
16
|
-
signDisplay:
|
|
17
|
-
}).resolvedOptions().signDisplay ===
|
|
15
|
+
$488c6ddbf4ef74c2$var$supportsSignDisplay = new Intl.NumberFormat('de-DE', {
|
|
16
|
+
signDisplay: 'exceptZero'
|
|
17
|
+
}).resolvedOptions().signDisplay === 'exceptZero';
|
|
18
18
|
// eslint-disable-next-line no-empty
|
|
19
19
|
} catch (e) {}
|
|
20
20
|
let $488c6ddbf4ef74c2$var$supportsUnit = false;
|
|
21
21
|
try {
|
|
22
22
|
// @ts-ignore
|
|
23
|
-
$488c6ddbf4ef74c2$var$supportsUnit = new Intl.NumberFormat(
|
|
24
|
-
style:
|
|
25
|
-
unit:
|
|
26
|
-
}).resolvedOptions().style ===
|
|
23
|
+
$488c6ddbf4ef74c2$var$supportsUnit = new Intl.NumberFormat('de-DE', {
|
|
24
|
+
style: 'unit',
|
|
25
|
+
unit: 'degree'
|
|
26
|
+
}).resolvedOptions().style === 'unit';
|
|
27
27
|
// eslint-disable-next-line no-empty
|
|
28
28
|
} catch (e) {}
|
|
29
29
|
// Polyfill for units since Safari doesn't support them yet. See https://bugs.webkit.org/show_bug.cgi?id=215438.
|
|
@@ -33,20 +33,20 @@ const $488c6ddbf4ef74c2$var$UNITS = {
|
|
|
33
33
|
degree: {
|
|
34
34
|
narrow: {
|
|
35
35
|
default: "\xb0",
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
'ja-JP': " \u5EA6",
|
|
37
|
+
'zh-TW': "\u5EA6",
|
|
38
|
+
'sl-SI': " \xb0"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
class $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 {
|
|
43
43
|
/** Formats a number value as a string, according to the locale and options provided to the constructor. */ format(value) {
|
|
44
|
-
let res =
|
|
44
|
+
let res = '';
|
|
45
45
|
if (!$488c6ddbf4ef74c2$var$supportsSignDisplay && this.options.signDisplay != null) res = $488c6ddbf4ef74c2$export$711b50b3c525e0f2(this.numberFormatter, this.options.signDisplay, value);
|
|
46
46
|
else res = this.numberFormatter.format(value);
|
|
47
|
-
if (this.options.style ===
|
|
47
|
+
if (this.options.style === 'unit' && !$488c6ddbf4ef74c2$var$supportsUnit) {
|
|
48
48
|
var _UNITS_unit;
|
|
49
|
-
let { unit: unit, unitDisplay: unitDisplay =
|
|
49
|
+
let { unit: unit, unitDisplay: unitDisplay = 'short', locale: locale } = this.resolvedOptions();
|
|
50
50
|
if (!unit) return res;
|
|
51
51
|
let values = (_UNITS_unit = $488c6ddbf4ef74c2$var$UNITS[unit]) === null || _UNITS_unit === void 0 ? void 0 : _UNITS_unit[unitDisplay];
|
|
52
52
|
res += values[locale] || values.default;
|
|
@@ -60,32 +60,32 @@ class $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 {
|
|
|
60
60
|
}
|
|
61
61
|
/** Formats a number range as a string. */ formatRange(start, end) {
|
|
62
62
|
// @ts-ignore
|
|
63
|
-
if (typeof this.numberFormatter.formatRange ===
|
|
63
|
+
if (typeof this.numberFormatter.formatRange === 'function') // @ts-ignore
|
|
64
64
|
return this.numberFormatter.formatRange(start, end);
|
|
65
|
-
if (end < start) throw new RangeError(
|
|
65
|
+
if (end < start) throw new RangeError('End date must be >= start date');
|
|
66
66
|
// Very basic fallback for old browsers.
|
|
67
67
|
return `${this.format(start)} \u{2013} ${this.format(end)}`;
|
|
68
68
|
}
|
|
69
69
|
/** Formats a number range as an array of parts. */ formatRangeToParts(start, end) {
|
|
70
70
|
// @ts-ignore
|
|
71
|
-
if (typeof this.numberFormatter.formatRangeToParts ===
|
|
71
|
+
if (typeof this.numberFormatter.formatRangeToParts === 'function') // @ts-ignore
|
|
72
72
|
return this.numberFormatter.formatRangeToParts(start, end);
|
|
73
|
-
if (end < start) throw new RangeError(
|
|
73
|
+
if (end < start) throw new RangeError('End date must be >= start date');
|
|
74
74
|
let startParts = this.numberFormatter.formatToParts(start);
|
|
75
75
|
let endParts = this.numberFormatter.formatToParts(end);
|
|
76
76
|
return [
|
|
77
77
|
...startParts.map((p)=>({
|
|
78
78
|
...p,
|
|
79
|
-
source:
|
|
79
|
+
source: 'startRange'
|
|
80
80
|
})),
|
|
81
81
|
{
|
|
82
|
-
type:
|
|
82
|
+
type: 'literal',
|
|
83
83
|
value: " \u2013 ",
|
|
84
|
-
source:
|
|
84
|
+
source: 'shared'
|
|
85
85
|
},
|
|
86
86
|
...endParts.map((p)=>({
|
|
87
87
|
...p,
|
|
88
|
-
source:
|
|
88
|
+
source: 'endRange'
|
|
89
89
|
}))
|
|
90
90
|
];
|
|
91
91
|
}
|
|
@@ -95,9 +95,9 @@ class $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 {
|
|
|
95
95
|
...options,
|
|
96
96
|
signDisplay: this.options.signDisplay
|
|
97
97
|
};
|
|
98
|
-
if (!$488c6ddbf4ef74c2$var$supportsUnit && this.options.style ===
|
|
98
|
+
if (!$488c6ddbf4ef74c2$var$supportsUnit && this.options.style === 'unit') options = {
|
|
99
99
|
...options,
|
|
100
|
-
style:
|
|
100
|
+
style: 'unit',
|
|
101
101
|
unit: this.options.unit,
|
|
102
102
|
unitDisplay: this.options.unitDisplay
|
|
103
103
|
};
|
|
@@ -110,33 +110,33 @@ class $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 {
|
|
|
110
110
|
}
|
|
111
111
|
function $488c6ddbf4ef74c2$var$getCachedNumberFormatter(locale, options = {}) {
|
|
112
112
|
let { numberingSystem: numberingSystem } = options;
|
|
113
|
-
if (numberingSystem && locale.includes(
|
|
114
|
-
if (!locale.includes(
|
|
113
|
+
if (numberingSystem && locale.includes('-nu-')) {
|
|
114
|
+
if (!locale.includes('-u-')) locale += '-u-';
|
|
115
115
|
locale += `-nu-${numberingSystem}`;
|
|
116
116
|
}
|
|
117
|
-
if (options.style ===
|
|
117
|
+
if (options.style === 'unit' && !$488c6ddbf4ef74c2$var$supportsUnit) {
|
|
118
118
|
var _UNITS_unit;
|
|
119
|
-
let { unit: unit, unitDisplay: unitDisplay =
|
|
119
|
+
let { unit: unit, unitDisplay: unitDisplay = 'short' } = options;
|
|
120
120
|
if (!unit) throw new Error('unit option must be provided with style: "unit"');
|
|
121
121
|
if (!((_UNITS_unit = $488c6ddbf4ef74c2$var$UNITS[unit]) === null || _UNITS_unit === void 0 ? void 0 : _UNITS_unit[unitDisplay])) throw new Error(`Unsupported unit ${unit} with unitDisplay = ${unitDisplay}`);
|
|
122
122
|
options = {
|
|
123
123
|
...options,
|
|
124
|
-
style:
|
|
124
|
+
style: 'decimal'
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
|
-
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() :
|
|
127
|
+
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() : '');
|
|
128
128
|
if ($488c6ddbf4ef74c2$var$formatterCache.has(cacheKey)) return $488c6ddbf4ef74c2$var$formatterCache.get(cacheKey);
|
|
129
129
|
let numberFormatter = new Intl.NumberFormat(locale, options);
|
|
130
130
|
$488c6ddbf4ef74c2$var$formatterCache.set(cacheKey, numberFormatter);
|
|
131
131
|
return numberFormatter;
|
|
132
132
|
}
|
|
133
133
|
function $488c6ddbf4ef74c2$export$711b50b3c525e0f2(numberFormat, signDisplay, num) {
|
|
134
|
-
if (signDisplay ===
|
|
135
|
-
else if (signDisplay ===
|
|
134
|
+
if (signDisplay === 'auto') return numberFormat.format(num);
|
|
135
|
+
else if (signDisplay === 'never') return numberFormat.format(Math.abs(num));
|
|
136
136
|
else {
|
|
137
137
|
let needsPositiveSign = false;
|
|
138
|
-
if (signDisplay ===
|
|
139
|
-
else if (signDisplay ===
|
|
138
|
+
if (signDisplay === 'always') needsPositiveSign = num > 0 || Object.is(num, 0);
|
|
139
|
+
else if (signDisplay === 'exceptZero') {
|
|
140
140
|
if (Object.is(num, -0) || Object.is(num, 0)) num = Math.abs(num);
|
|
141
141
|
else needsPositiveSign = num > 0;
|
|
142
142
|
}
|
|
@@ -144,11 +144,11 @@ function $488c6ddbf4ef74c2$export$711b50b3c525e0f2(numberFormat, signDisplay, nu
|
|
|
144
144
|
let negative = numberFormat.format(-num);
|
|
145
145
|
let noSign = numberFormat.format(num);
|
|
146
146
|
// ignore RTL/LTR marker character
|
|
147
|
-
let minus = negative.replace(noSign,
|
|
147
|
+
let minus = negative.replace(noSign, '').replace(/\u200e|\u061C/, '');
|
|
148
148
|
if ([
|
|
149
149
|
...minus
|
|
150
|
-
].length !== 1) console.warn(
|
|
151
|
-
let positive = negative.replace(noSign,
|
|
150
|
+
].length !== 1) console.warn('@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case');
|
|
151
|
+
let positive = negative.replace(noSign, '!!!').replace(minus, '+').replace('!!!', noSign);
|
|
152
152
|
return positive;
|
|
153
153
|
} else return numberFormat.format(num);
|
|
154
154
|
}
|
|
@@ -17,11 +17,11 @@ $parcel$export(module.exports, "NumberParser", () => $d68f3f4c684426c6$export$cd
|
|
|
17
17
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
18
|
* governing permissions and limitations under the License.
|
|
19
19
|
*/
|
|
20
|
-
const $d68f3f4c684426c6$var$CURRENCY_SIGN_REGEX = new RegExp(
|
|
20
|
+
const $d68f3f4c684426c6$var$CURRENCY_SIGN_REGEX = new RegExp('^.*\\(.*\\).*$');
|
|
21
21
|
const $d68f3f4c684426c6$var$NUMBERING_SYSTEMS = [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
'latn',
|
|
23
|
+
'arab',
|
|
24
|
+
'hanidec'
|
|
25
25
|
];
|
|
26
26
|
class $d68f3f4c684426c6$export$cd11ab140839f11d {
|
|
27
27
|
/**
|
|
@@ -54,16 +54,16 @@ function $d68f3f4c684426c6$var$getNumberParserImpl(locale, options, value) {
|
|
|
54
54
|
let defaultParser = $d68f3f4c684426c6$var$getCachedNumberParser(locale, options);
|
|
55
55
|
// If that doesn't match, and the locale doesn't include a hard coded numbering system,
|
|
56
56
|
// try each of the other supported numbering systems until we find one that matches.
|
|
57
|
-
if (!locale.includes(
|
|
57
|
+
if (!locale.includes('-nu-') && !defaultParser.isValidPartialNumber(value)) {
|
|
58
58
|
for (let numberingSystem of $d68f3f4c684426c6$var$NUMBERING_SYSTEMS)if (numberingSystem !== defaultParser.options.numberingSystem) {
|
|
59
|
-
let parser = $d68f3f4c684426c6$var$getCachedNumberParser(locale + (locale.includes(
|
|
59
|
+
let parser = $d68f3f4c684426c6$var$getCachedNumberParser(locale + (locale.includes('-u-') ? '-nu-' : '-u-nu-') + numberingSystem, options);
|
|
60
60
|
if (parser.isValidPartialNumber(value)) return parser;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
return defaultParser;
|
|
64
64
|
}
|
|
65
65
|
function $d68f3f4c684426c6$var$getCachedNumberParser(locale, options) {
|
|
66
|
-
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() :
|
|
66
|
+
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() : '');
|
|
67
67
|
let parser = $d68f3f4c684426c6$var$numberParserCache.get(cacheKey);
|
|
68
68
|
if (!parser) {
|
|
69
69
|
parser = new $d68f3f4c684426c6$var$NumberParserImpl(locale, options);
|
|
@@ -78,58 +78,58 @@ class $d68f3f4c684426c6$var$NumberParserImpl {
|
|
|
78
78
|
// to parse the number, we need to remove anything that isn't actually part of the number, for example we want '-10.40' not '-10.40 USD'
|
|
79
79
|
let fullySanitizedValue = this.sanitize(value);
|
|
80
80
|
if (this.symbols.group) // Remove group characters, and replace decimal points and numerals with ASCII values.
|
|
81
|
-
fullySanitizedValue = $d68f3f4c684426c6$var$replaceAll(fullySanitizedValue, this.symbols.group,
|
|
82
|
-
if (this.symbols.decimal) fullySanitizedValue = fullySanitizedValue.replace(this.symbols.decimal,
|
|
83
|
-
if (this.symbols.minusSign) fullySanitizedValue = fullySanitizedValue.replace(this.symbols.minusSign,
|
|
81
|
+
fullySanitizedValue = $d68f3f4c684426c6$var$replaceAll(fullySanitizedValue, this.symbols.group, '');
|
|
82
|
+
if (this.symbols.decimal) fullySanitizedValue = fullySanitizedValue.replace(this.symbols.decimal, '.');
|
|
83
|
+
if (this.symbols.minusSign) fullySanitizedValue = fullySanitizedValue.replace(this.symbols.minusSign, '-');
|
|
84
84
|
fullySanitizedValue = fullySanitizedValue.replace(this.symbols.numeral, this.symbols.index);
|
|
85
|
-
if (this.options.style ===
|
|
85
|
+
if (this.options.style === 'percent') {
|
|
86
86
|
// javascript is bad at dividing by 100 and maintaining the same significant figures, so perform it on the string before parsing
|
|
87
|
-
let isNegative = fullySanitizedValue.indexOf(
|
|
88
|
-
fullySanitizedValue = fullySanitizedValue.replace(
|
|
89
|
-
let index = fullySanitizedValue.indexOf(
|
|
87
|
+
let isNegative = fullySanitizedValue.indexOf('-');
|
|
88
|
+
fullySanitizedValue = fullySanitizedValue.replace('-', '');
|
|
89
|
+
let index = fullySanitizedValue.indexOf('.');
|
|
90
90
|
if (index === -1) index = fullySanitizedValue.length;
|
|
91
|
-
fullySanitizedValue = fullySanitizedValue.replace(
|
|
91
|
+
fullySanitizedValue = fullySanitizedValue.replace('.', '');
|
|
92
92
|
if (index - 2 === 0) fullySanitizedValue = `0.${fullySanitizedValue}`;
|
|
93
93
|
else if (index - 2 === -1) fullySanitizedValue = `0.0${fullySanitizedValue}`;
|
|
94
|
-
else if (index - 2 === -2) fullySanitizedValue =
|
|
94
|
+
else if (index - 2 === -2) fullySanitizedValue = '0.00';
|
|
95
95
|
else fullySanitizedValue = `${fullySanitizedValue.slice(0, index - 2)}.${fullySanitizedValue.slice(index - 2)}`;
|
|
96
96
|
if (isNegative > -1) fullySanitizedValue = `-${fullySanitizedValue}`;
|
|
97
97
|
}
|
|
98
98
|
let newValue = fullySanitizedValue ? +fullySanitizedValue : NaN;
|
|
99
99
|
if (isNaN(newValue)) return NaN;
|
|
100
|
-
if (this.options.style ===
|
|
100
|
+
if (this.options.style === 'percent') {
|
|
101
101
|
var _this_options_minimumFractionDigits, _this_options_maximumFractionDigits;
|
|
102
102
|
// extra step for rounding percents to what our formatter would output
|
|
103
103
|
let options = {
|
|
104
104
|
...this.options,
|
|
105
|
-
style:
|
|
105
|
+
style: 'decimal',
|
|
106
106
|
minimumFractionDigits: Math.min(((_this_options_minimumFractionDigits = this.options.minimumFractionDigits) !== null && _this_options_minimumFractionDigits !== void 0 ? _this_options_minimumFractionDigits : 0) + 2, 20),
|
|
107
107
|
maximumFractionDigits: Math.min(((_this_options_maximumFractionDigits = this.options.maximumFractionDigits) !== null && _this_options_maximumFractionDigits !== void 0 ? _this_options_maximumFractionDigits : 0) + 2, 20)
|
|
108
108
|
};
|
|
109
109
|
return new $d68f3f4c684426c6$export$cd11ab140839f11d(this.locale, options).parse(new (0, $0c1d5654b62fc485$exports.NumberFormatter)(this.locale, options).format(newValue));
|
|
110
110
|
}
|
|
111
111
|
// accounting will always be stripped to a positive number, so if it's accounting and has a () around everything, then we need to make it negative again
|
|
112
|
-
if (this.options.currencySign ===
|
|
112
|
+
if (this.options.currencySign === 'accounting' && $d68f3f4c684426c6$var$CURRENCY_SIGN_REGEX.test(value)) newValue = -1 * newValue;
|
|
113
113
|
return newValue;
|
|
114
114
|
}
|
|
115
115
|
sanitize(value) {
|
|
116
116
|
// Remove literals and whitespace, which are allowed anywhere in the string
|
|
117
|
-
value = value.replace(this.symbols.literals,
|
|
117
|
+
value = value.replace(this.symbols.literals, '');
|
|
118
118
|
// Replace the ASCII minus sign with the minus sign used in the current locale
|
|
119
119
|
// so that both are allowed in case the user's keyboard doesn't have the locale's minus sign.
|
|
120
|
-
if (this.symbols.minusSign) value = value.replace(
|
|
120
|
+
if (this.symbols.minusSign) value = value.replace('-', this.symbols.minusSign);
|
|
121
121
|
// In arab numeral system, their decimal character is 1643, but most keyboards don't type that
|
|
122
122
|
// instead they use the , (44) character or apparently the (1548) character.
|
|
123
|
-
if (this.options.numberingSystem ===
|
|
123
|
+
if (this.options.numberingSystem === 'arab') {
|
|
124
124
|
if (this.symbols.decimal) {
|
|
125
|
-
value = value.replace(
|
|
125
|
+
value = value.replace(',', this.symbols.decimal);
|
|
126
126
|
value = value.replace(String.fromCharCode(1548), this.symbols.decimal);
|
|
127
127
|
}
|
|
128
|
-
if (this.symbols.group) value = $d68f3f4c684426c6$var$replaceAll(value,
|
|
128
|
+
if (this.symbols.group) value = $d68f3f4c684426c6$var$replaceAll(value, '.', this.symbols.group);
|
|
129
129
|
}
|
|
130
130
|
// fr-FR group character is char code 8239, but that's not a key on the french keyboard,
|
|
131
131
|
// so allow 'period' as a group char and replace it with a space
|
|
132
|
-
if (this.options.locale ===
|
|
132
|
+
if (this.options.locale === 'fr-FR') value = $d68f3f4c684426c6$var$replaceAll(value, '.', String.fromCharCode(8239));
|
|
133
133
|
return value;
|
|
134
134
|
}
|
|
135
135
|
isValidPartialNumber(value, minValue = -Infinity, maxValue = Infinity) {
|
|
@@ -142,9 +142,9 @@ class $d68f3f4c684426c6$var$NumberParserImpl {
|
|
|
142
142
|
// Numbers that can't have any decimal values fail if a decimal character is typed
|
|
143
143
|
if (this.symbols.decimal && value.indexOf(this.symbols.decimal) > -1 && this.options.maximumFractionDigits === 0) return false;
|
|
144
144
|
// Remove numerals, groups, and decimals
|
|
145
|
-
if (this.symbols.group) value = $d68f3f4c684426c6$var$replaceAll(value, this.symbols.group,
|
|
146
|
-
value = value.replace(this.symbols.numeral,
|
|
147
|
-
if (this.symbols.decimal) value = value.replace(this.symbols.decimal,
|
|
145
|
+
if (this.symbols.group) value = $d68f3f4c684426c6$var$replaceAll(value, this.symbols.group, '');
|
|
146
|
+
value = value.replace(this.symbols.numeral, '');
|
|
147
|
+
if (this.symbols.decimal) value = value.replace(this.symbols.decimal, '');
|
|
148
148
|
// The number is valid if there are no remaining characters
|
|
149
149
|
return value.length === 0;
|
|
150
150
|
}
|
|
@@ -154,16 +154,16 @@ class $d68f3f4c684426c6$var$NumberParserImpl {
|
|
|
154
154
|
this.options = this.formatter.resolvedOptions();
|
|
155
155
|
this.symbols = $d68f3f4c684426c6$var$getSymbols(locale, this.formatter, this.options, options);
|
|
156
156
|
var _this_options_minimumFractionDigits, _this_options_maximumFractionDigits;
|
|
157
|
-
if (this.options.style ===
|
|
157
|
+
if (this.options.style === 'percent' && (((_this_options_minimumFractionDigits = this.options.minimumFractionDigits) !== null && _this_options_minimumFractionDigits !== void 0 ? _this_options_minimumFractionDigits : 0) > 18 || ((_this_options_maximumFractionDigits = this.options.maximumFractionDigits) !== null && _this_options_maximumFractionDigits !== void 0 ? _this_options_maximumFractionDigits : 0) > 18)) console.warn('NumberParser cannot handle percentages with greater than 18 decimal places, please reduce the number in your options.');
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
const $d68f3f4c684426c6$var$nonLiteralParts = new Set([
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
161
|
+
'decimal',
|
|
162
|
+
'fraction',
|
|
163
|
+
'integer',
|
|
164
|
+
'minusSign',
|
|
165
|
+
'plusSign',
|
|
166
|
+
'group'
|
|
167
167
|
]);
|
|
168
168
|
// This list is derived from https://www.unicode.org/cldr/charts/43/supplemental/language_plural_rules.html#comparison and includes
|
|
169
169
|
// all unique numbers which we need to check in order to determine all the plural forms for a given locale.
|
|
@@ -195,12 +195,12 @@ function $d68f3f4c684426c6$var$getSymbols(locale, formatter, intlOptions, origin
|
|
|
195
195
|
let posAllParts = symbolFormatter.formatToParts(10000.111);
|
|
196
196
|
let pluralParts = $d68f3f4c684426c6$var$pluralNumbers.map((n)=>symbolFormatter.formatToParts(n));
|
|
197
197
|
var _allParts_find_value;
|
|
198
|
-
let minusSign = (_allParts_find_value = (_allParts_find = allParts.find((p)=>p.type ===
|
|
199
|
-
let plusSign = (_posAllParts_find = posAllParts.find((p)=>p.type ===
|
|
198
|
+
let minusSign = (_allParts_find_value = (_allParts_find = allParts.find((p)=>p.type === 'minusSign')) === null || _allParts_find === void 0 ? void 0 : _allParts_find.value) !== null && _allParts_find_value !== void 0 ? _allParts_find_value : '-';
|
|
199
|
+
let plusSign = (_posAllParts_find = posAllParts.find((p)=>p.type === 'plusSign')) === null || _posAllParts_find === void 0 ? void 0 : _posAllParts_find.value;
|
|
200
200
|
// Safari does not support the signDisplay option, but our number parser polyfills it.
|
|
201
201
|
// If no plus sign was returned, but the original options contained signDisplay, default to the '+' character.
|
|
202
202
|
// @ts-ignore
|
|
203
|
-
if (!plusSign && ((originalOptions === null || originalOptions === void 0 ? void 0 : originalOptions.signDisplay) ===
|
|
203
|
+
if (!plusSign && ((originalOptions === null || originalOptions === void 0 ? void 0 : originalOptions.signDisplay) === 'exceptZero' || (originalOptions === null || originalOptions === void 0 ? void 0 : originalOptions.signDisplay) === 'always')) plusSign = '+';
|
|
204
204
|
// If maximumSignificantDigits is 1 (the minimum) then we won't get decimal characters out of the above formatters
|
|
205
205
|
// Percent also defaults to 0 fractionDigits, so we need to make a new one that isn't percent to get an accurate decimal
|
|
206
206
|
let decimalParts = new Intl.NumberFormat(locale, {
|
|
@@ -208,8 +208,8 @@ function $d68f3f4c684426c6$var$getSymbols(locale, formatter, intlOptions, origin
|
|
|
208
208
|
minimumFractionDigits: 2,
|
|
209
209
|
maximumFractionDigits: 2
|
|
210
210
|
}).formatToParts(0.001);
|
|
211
|
-
let decimal = (_decimalParts_find = decimalParts.find((p)=>p.type ===
|
|
212
|
-
let group = (_allParts_find1 = allParts.find((p)=>p.type ===
|
|
211
|
+
let decimal = (_decimalParts_find = decimalParts.find((p)=>p.type === 'decimal')) === null || _decimalParts_find === void 0 ? void 0 : _decimalParts_find.value;
|
|
212
|
+
let group = (_allParts_find1 = allParts.find((p)=>p.type === 'group')) === null || _allParts_find1 === void 0 ? void 0 : _allParts_find1.value;
|
|
213
213
|
// this set is also for a regex, it's all literals that might be in the string we want to eventually parse that
|
|
214
214
|
// don't contribute to the numerical value
|
|
215
215
|
let allPartsLiterals = allParts.filter((p)=>!$d68f3f4c684426c6$var$nonLiteralParts.has(p.type)).map((p)=>$d68f3f4c684426c6$var$escapeRegex(p.value));
|
|
@@ -220,7 +220,7 @@ function $d68f3f4c684426c6$var$getSymbols(locale, formatter, intlOptions, origin
|
|
|
220
220
|
...pluralPartsLiterals
|
|
221
221
|
])
|
|
222
222
|
].sort((a, b)=>b.length - a.length);
|
|
223
|
-
let literals = sortedLiterals.length === 0 ? new RegExp(
|
|
223
|
+
let literals = sortedLiterals.length === 0 ? new RegExp('[\\p{White_Space}]', 'gu') : new RegExp(`${sortedLiterals.join('|')}|[\\p{White_Space}]`, 'gu');
|
|
224
224
|
// These are for replacing non-latn characters with the latn equivalent
|
|
225
225
|
let numerals = [
|
|
226
226
|
...new Intl.NumberFormat(intlOptions.locale, {
|
|
@@ -231,7 +231,7 @@ function $d68f3f4c684426c6$var$getSymbols(locale, formatter, intlOptions, origin
|
|
|
231
231
|
d,
|
|
232
232
|
i
|
|
233
233
|
]));
|
|
234
|
-
let numeral = new RegExp(`[${numerals.join(
|
|
234
|
+
let numeral = new RegExp(`[${numerals.join('')}]`, 'g');
|
|
235
235
|
let index = (d)=>String(indexes.get(d));
|
|
236
236
|
return {
|
|
237
237
|
minusSign: minusSign,
|
|
@@ -250,7 +250,7 @@ function $d68f3f4c684426c6$var$replaceAll(str, find, replace) {
|
|
|
250
250
|
return str.split(find).join(replace);
|
|
251
251
|
}
|
|
252
252
|
function $d68f3f4c684426c6$var$escapeRegex(string) {
|
|
253
|
-
return string.replace(/[.*+?^${}()|[\]\\]/g,
|
|
253
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
|
package/dist/NumberParser.mjs
CHANGED
|
@@ -11,11 +11,11 @@ import {NumberFormatter as $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5} from "./Nu
|
|
|
11
11
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
|
-
const $6c7bd7858deea686$var$CURRENCY_SIGN_REGEX = new RegExp(
|
|
14
|
+
const $6c7bd7858deea686$var$CURRENCY_SIGN_REGEX = new RegExp('^.*\\(.*\\).*$');
|
|
15
15
|
const $6c7bd7858deea686$var$NUMBERING_SYSTEMS = [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
'latn',
|
|
17
|
+
'arab',
|
|
18
|
+
'hanidec'
|
|
19
19
|
];
|
|
20
20
|
class $6c7bd7858deea686$export$cd11ab140839f11d {
|
|
21
21
|
/**
|
|
@@ -48,16 +48,16 @@ function $6c7bd7858deea686$var$getNumberParserImpl(locale, options, value) {
|
|
|
48
48
|
let defaultParser = $6c7bd7858deea686$var$getCachedNumberParser(locale, options);
|
|
49
49
|
// If that doesn't match, and the locale doesn't include a hard coded numbering system,
|
|
50
50
|
// try each of the other supported numbering systems until we find one that matches.
|
|
51
|
-
if (!locale.includes(
|
|
51
|
+
if (!locale.includes('-nu-') && !defaultParser.isValidPartialNumber(value)) {
|
|
52
52
|
for (let numberingSystem of $6c7bd7858deea686$var$NUMBERING_SYSTEMS)if (numberingSystem !== defaultParser.options.numberingSystem) {
|
|
53
|
-
let parser = $6c7bd7858deea686$var$getCachedNumberParser(locale + (locale.includes(
|
|
53
|
+
let parser = $6c7bd7858deea686$var$getCachedNumberParser(locale + (locale.includes('-u-') ? '-nu-' : '-u-nu-') + numberingSystem, options);
|
|
54
54
|
if (parser.isValidPartialNumber(value)) return parser;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
return defaultParser;
|
|
58
58
|
}
|
|
59
59
|
function $6c7bd7858deea686$var$getCachedNumberParser(locale, options) {
|
|
60
|
-
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() :
|
|
60
|
+
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() : '');
|
|
61
61
|
let parser = $6c7bd7858deea686$var$numberParserCache.get(cacheKey);
|
|
62
62
|
if (!parser) {
|
|
63
63
|
parser = new $6c7bd7858deea686$var$NumberParserImpl(locale, options);
|
|
@@ -72,58 +72,58 @@ class $6c7bd7858deea686$var$NumberParserImpl {
|
|
|
72
72
|
// to parse the number, we need to remove anything that isn't actually part of the number, for example we want '-10.40' not '-10.40 USD'
|
|
73
73
|
let fullySanitizedValue = this.sanitize(value);
|
|
74
74
|
if (this.symbols.group) // Remove group characters, and replace decimal points and numerals with ASCII values.
|
|
75
|
-
fullySanitizedValue = $6c7bd7858deea686$var$replaceAll(fullySanitizedValue, this.symbols.group,
|
|
76
|
-
if (this.symbols.decimal) fullySanitizedValue = fullySanitizedValue.replace(this.symbols.decimal,
|
|
77
|
-
if (this.symbols.minusSign) fullySanitizedValue = fullySanitizedValue.replace(this.symbols.minusSign,
|
|
75
|
+
fullySanitizedValue = $6c7bd7858deea686$var$replaceAll(fullySanitizedValue, this.symbols.group, '');
|
|
76
|
+
if (this.symbols.decimal) fullySanitizedValue = fullySanitizedValue.replace(this.symbols.decimal, '.');
|
|
77
|
+
if (this.symbols.minusSign) fullySanitizedValue = fullySanitizedValue.replace(this.symbols.minusSign, '-');
|
|
78
78
|
fullySanitizedValue = fullySanitizedValue.replace(this.symbols.numeral, this.symbols.index);
|
|
79
|
-
if (this.options.style ===
|
|
79
|
+
if (this.options.style === 'percent') {
|
|
80
80
|
// javascript is bad at dividing by 100 and maintaining the same significant figures, so perform it on the string before parsing
|
|
81
|
-
let isNegative = fullySanitizedValue.indexOf(
|
|
82
|
-
fullySanitizedValue = fullySanitizedValue.replace(
|
|
83
|
-
let index = fullySanitizedValue.indexOf(
|
|
81
|
+
let isNegative = fullySanitizedValue.indexOf('-');
|
|
82
|
+
fullySanitizedValue = fullySanitizedValue.replace('-', '');
|
|
83
|
+
let index = fullySanitizedValue.indexOf('.');
|
|
84
84
|
if (index === -1) index = fullySanitizedValue.length;
|
|
85
|
-
fullySanitizedValue = fullySanitizedValue.replace(
|
|
85
|
+
fullySanitizedValue = fullySanitizedValue.replace('.', '');
|
|
86
86
|
if (index - 2 === 0) fullySanitizedValue = `0.${fullySanitizedValue}`;
|
|
87
87
|
else if (index - 2 === -1) fullySanitizedValue = `0.0${fullySanitizedValue}`;
|
|
88
|
-
else if (index - 2 === -2) fullySanitizedValue =
|
|
88
|
+
else if (index - 2 === -2) fullySanitizedValue = '0.00';
|
|
89
89
|
else fullySanitizedValue = `${fullySanitizedValue.slice(0, index - 2)}.${fullySanitizedValue.slice(index - 2)}`;
|
|
90
90
|
if (isNegative > -1) fullySanitizedValue = `-${fullySanitizedValue}`;
|
|
91
91
|
}
|
|
92
92
|
let newValue = fullySanitizedValue ? +fullySanitizedValue : NaN;
|
|
93
93
|
if (isNaN(newValue)) return NaN;
|
|
94
|
-
if (this.options.style ===
|
|
94
|
+
if (this.options.style === 'percent') {
|
|
95
95
|
var _this_options_minimumFractionDigits, _this_options_maximumFractionDigits;
|
|
96
96
|
// extra step for rounding percents to what our formatter would output
|
|
97
97
|
let options = {
|
|
98
98
|
...this.options,
|
|
99
|
-
style:
|
|
99
|
+
style: 'decimal',
|
|
100
100
|
minimumFractionDigits: Math.min(((_this_options_minimumFractionDigits = this.options.minimumFractionDigits) !== null && _this_options_minimumFractionDigits !== void 0 ? _this_options_minimumFractionDigits : 0) + 2, 20),
|
|
101
101
|
maximumFractionDigits: Math.min(((_this_options_maximumFractionDigits = this.options.maximumFractionDigits) !== null && _this_options_maximumFractionDigits !== void 0 ? _this_options_maximumFractionDigits : 0) + 2, 20)
|
|
102
102
|
};
|
|
103
103
|
return new $6c7bd7858deea686$export$cd11ab140839f11d(this.locale, options).parse(new (0, $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5)(this.locale, options).format(newValue));
|
|
104
104
|
}
|
|
105
105
|
// accounting will always be stripped to a positive number, so if it's accounting and has a () around everything, then we need to make it negative again
|
|
106
|
-
if (this.options.currencySign ===
|
|
106
|
+
if (this.options.currencySign === 'accounting' && $6c7bd7858deea686$var$CURRENCY_SIGN_REGEX.test(value)) newValue = -1 * newValue;
|
|
107
107
|
return newValue;
|
|
108
108
|
}
|
|
109
109
|
sanitize(value) {
|
|
110
110
|
// Remove literals and whitespace, which are allowed anywhere in the string
|
|
111
|
-
value = value.replace(this.symbols.literals,
|
|
111
|
+
value = value.replace(this.symbols.literals, '');
|
|
112
112
|
// Replace the ASCII minus sign with the minus sign used in the current locale
|
|
113
113
|
// so that both are allowed in case the user's keyboard doesn't have the locale's minus sign.
|
|
114
|
-
if (this.symbols.minusSign) value = value.replace(
|
|
114
|
+
if (this.symbols.minusSign) value = value.replace('-', this.symbols.minusSign);
|
|
115
115
|
// In arab numeral system, their decimal character is 1643, but most keyboards don't type that
|
|
116
116
|
// instead they use the , (44) character or apparently the (1548) character.
|
|
117
|
-
if (this.options.numberingSystem ===
|
|
117
|
+
if (this.options.numberingSystem === 'arab') {
|
|
118
118
|
if (this.symbols.decimal) {
|
|
119
|
-
value = value.replace(
|
|
119
|
+
value = value.replace(',', this.symbols.decimal);
|
|
120
120
|
value = value.replace(String.fromCharCode(1548), this.symbols.decimal);
|
|
121
121
|
}
|
|
122
|
-
if (this.symbols.group) value = $6c7bd7858deea686$var$replaceAll(value,
|
|
122
|
+
if (this.symbols.group) value = $6c7bd7858deea686$var$replaceAll(value, '.', this.symbols.group);
|
|
123
123
|
}
|
|
124
124
|
// fr-FR group character is char code 8239, but that's not a key on the french keyboard,
|
|
125
125
|
// so allow 'period' as a group char and replace it with a space
|
|
126
|
-
if (this.options.locale ===
|
|
126
|
+
if (this.options.locale === 'fr-FR') value = $6c7bd7858deea686$var$replaceAll(value, '.', String.fromCharCode(8239));
|
|
127
127
|
return value;
|
|
128
128
|
}
|
|
129
129
|
isValidPartialNumber(value, minValue = -Infinity, maxValue = Infinity) {
|
|
@@ -136,9 +136,9 @@ class $6c7bd7858deea686$var$NumberParserImpl {
|
|
|
136
136
|
// Numbers that can't have any decimal values fail if a decimal character is typed
|
|
137
137
|
if (this.symbols.decimal && value.indexOf(this.symbols.decimal) > -1 && this.options.maximumFractionDigits === 0) return false;
|
|
138
138
|
// Remove numerals, groups, and decimals
|
|
139
|
-
if (this.symbols.group) value = $6c7bd7858deea686$var$replaceAll(value, this.symbols.group,
|
|
140
|
-
value = value.replace(this.symbols.numeral,
|
|
141
|
-
if (this.symbols.decimal) value = value.replace(this.symbols.decimal,
|
|
139
|
+
if (this.symbols.group) value = $6c7bd7858deea686$var$replaceAll(value, this.symbols.group, '');
|
|
140
|
+
value = value.replace(this.symbols.numeral, '');
|
|
141
|
+
if (this.symbols.decimal) value = value.replace(this.symbols.decimal, '');
|
|
142
142
|
// The number is valid if there are no remaining characters
|
|
143
143
|
return value.length === 0;
|
|
144
144
|
}
|
|
@@ -148,16 +148,16 @@ class $6c7bd7858deea686$var$NumberParserImpl {
|
|
|
148
148
|
this.options = this.formatter.resolvedOptions();
|
|
149
149
|
this.symbols = $6c7bd7858deea686$var$getSymbols(locale, this.formatter, this.options, options);
|
|
150
150
|
var _this_options_minimumFractionDigits, _this_options_maximumFractionDigits;
|
|
151
|
-
if (this.options.style ===
|
|
151
|
+
if (this.options.style === 'percent' && (((_this_options_minimumFractionDigits = this.options.minimumFractionDigits) !== null && _this_options_minimumFractionDigits !== void 0 ? _this_options_minimumFractionDigits : 0) > 18 || ((_this_options_maximumFractionDigits = this.options.maximumFractionDigits) !== null && _this_options_maximumFractionDigits !== void 0 ? _this_options_maximumFractionDigits : 0) > 18)) console.warn('NumberParser cannot handle percentages with greater than 18 decimal places, please reduce the number in your options.');
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
const $6c7bd7858deea686$var$nonLiteralParts = new Set([
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
155
|
+
'decimal',
|
|
156
|
+
'fraction',
|
|
157
|
+
'integer',
|
|
158
|
+
'minusSign',
|
|
159
|
+
'plusSign',
|
|
160
|
+
'group'
|
|
161
161
|
]);
|
|
162
162
|
// This list is derived from https://www.unicode.org/cldr/charts/43/supplemental/language_plural_rules.html#comparison and includes
|
|
163
163
|
// all unique numbers which we need to check in order to determine all the plural forms for a given locale.
|
|
@@ -189,12 +189,12 @@ function $6c7bd7858deea686$var$getSymbols(locale, formatter, intlOptions, origin
|
|
|
189
189
|
let posAllParts = symbolFormatter.formatToParts(10000.111);
|
|
190
190
|
let pluralParts = $6c7bd7858deea686$var$pluralNumbers.map((n)=>symbolFormatter.formatToParts(n));
|
|
191
191
|
var _allParts_find_value;
|
|
192
|
-
let minusSign = (_allParts_find_value = (_allParts_find = allParts.find((p)=>p.type ===
|
|
193
|
-
let plusSign = (_posAllParts_find = posAllParts.find((p)=>p.type ===
|
|
192
|
+
let minusSign = (_allParts_find_value = (_allParts_find = allParts.find((p)=>p.type === 'minusSign')) === null || _allParts_find === void 0 ? void 0 : _allParts_find.value) !== null && _allParts_find_value !== void 0 ? _allParts_find_value : '-';
|
|
193
|
+
let plusSign = (_posAllParts_find = posAllParts.find((p)=>p.type === 'plusSign')) === null || _posAllParts_find === void 0 ? void 0 : _posAllParts_find.value;
|
|
194
194
|
// Safari does not support the signDisplay option, but our number parser polyfills it.
|
|
195
195
|
// If no plus sign was returned, but the original options contained signDisplay, default to the '+' character.
|
|
196
196
|
// @ts-ignore
|
|
197
|
-
if (!plusSign && ((originalOptions === null || originalOptions === void 0 ? void 0 : originalOptions.signDisplay) ===
|
|
197
|
+
if (!plusSign && ((originalOptions === null || originalOptions === void 0 ? void 0 : originalOptions.signDisplay) === 'exceptZero' || (originalOptions === null || originalOptions === void 0 ? void 0 : originalOptions.signDisplay) === 'always')) plusSign = '+';
|
|
198
198
|
// If maximumSignificantDigits is 1 (the minimum) then we won't get decimal characters out of the above formatters
|
|
199
199
|
// Percent also defaults to 0 fractionDigits, so we need to make a new one that isn't percent to get an accurate decimal
|
|
200
200
|
let decimalParts = new Intl.NumberFormat(locale, {
|
|
@@ -202,8 +202,8 @@ function $6c7bd7858deea686$var$getSymbols(locale, formatter, intlOptions, origin
|
|
|
202
202
|
minimumFractionDigits: 2,
|
|
203
203
|
maximumFractionDigits: 2
|
|
204
204
|
}).formatToParts(0.001);
|
|
205
|
-
let decimal = (_decimalParts_find = decimalParts.find((p)=>p.type ===
|
|
206
|
-
let group = (_allParts_find1 = allParts.find((p)=>p.type ===
|
|
205
|
+
let decimal = (_decimalParts_find = decimalParts.find((p)=>p.type === 'decimal')) === null || _decimalParts_find === void 0 ? void 0 : _decimalParts_find.value;
|
|
206
|
+
let group = (_allParts_find1 = allParts.find((p)=>p.type === 'group')) === null || _allParts_find1 === void 0 ? void 0 : _allParts_find1.value;
|
|
207
207
|
// this set is also for a regex, it's all literals that might be in the string we want to eventually parse that
|
|
208
208
|
// don't contribute to the numerical value
|
|
209
209
|
let allPartsLiterals = allParts.filter((p)=>!$6c7bd7858deea686$var$nonLiteralParts.has(p.type)).map((p)=>$6c7bd7858deea686$var$escapeRegex(p.value));
|
|
@@ -214,7 +214,7 @@ function $6c7bd7858deea686$var$getSymbols(locale, formatter, intlOptions, origin
|
|
|
214
214
|
...pluralPartsLiterals
|
|
215
215
|
])
|
|
216
216
|
].sort((a, b)=>b.length - a.length);
|
|
217
|
-
let literals = sortedLiterals.length === 0 ? new RegExp(
|
|
217
|
+
let literals = sortedLiterals.length === 0 ? new RegExp('[\\p{White_Space}]', 'gu') : new RegExp(`${sortedLiterals.join('|')}|[\\p{White_Space}]`, 'gu');
|
|
218
218
|
// These are for replacing non-latn characters with the latn equivalent
|
|
219
219
|
let numerals = [
|
|
220
220
|
...new Intl.NumberFormat(intlOptions.locale, {
|
|
@@ -225,7 +225,7 @@ function $6c7bd7858deea686$var$getSymbols(locale, formatter, intlOptions, origin
|
|
|
225
225
|
d,
|
|
226
226
|
i
|
|
227
227
|
]));
|
|
228
|
-
let numeral = new RegExp(`[${numerals.join(
|
|
228
|
+
let numeral = new RegExp(`[${numerals.join('')}]`, 'g');
|
|
229
229
|
let index = (d)=>String(indexes.get(d));
|
|
230
230
|
return {
|
|
231
231
|
minusSign: minusSign,
|
|
@@ -244,7 +244,7 @@ function $6c7bd7858deea686$var$replaceAll(str, find, replace) {
|
|
|
244
244
|
return str.split(find).join(replace);
|
|
245
245
|
}
|
|
246
246
|
function $6c7bd7858deea686$var$escapeRegex(string) {
|
|
247
|
-
return string.replace(/[.*+?^${}()|[\]\\]/g,
|
|
247
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
|
|
@@ -11,11 +11,11 @@ import {NumberFormatter as $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5} from "./Nu
|
|
|
11
11
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
|
-
const $6c7bd7858deea686$var$CURRENCY_SIGN_REGEX = new RegExp(
|
|
14
|
+
const $6c7bd7858deea686$var$CURRENCY_SIGN_REGEX = new RegExp('^.*\\(.*\\).*$');
|
|
15
15
|
const $6c7bd7858deea686$var$NUMBERING_SYSTEMS = [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
'latn',
|
|
17
|
+
'arab',
|
|
18
|
+
'hanidec'
|
|
19
19
|
];
|
|
20
20
|
class $6c7bd7858deea686$export$cd11ab140839f11d {
|
|
21
21
|
/**
|
|
@@ -48,16 +48,16 @@ function $6c7bd7858deea686$var$getNumberParserImpl(locale, options, value) {
|
|
|
48
48
|
let defaultParser = $6c7bd7858deea686$var$getCachedNumberParser(locale, options);
|
|
49
49
|
// If that doesn't match, and the locale doesn't include a hard coded numbering system,
|
|
50
50
|
// try each of the other supported numbering systems until we find one that matches.
|
|
51
|
-
if (!locale.includes(
|
|
51
|
+
if (!locale.includes('-nu-') && !defaultParser.isValidPartialNumber(value)) {
|
|
52
52
|
for (let numberingSystem of $6c7bd7858deea686$var$NUMBERING_SYSTEMS)if (numberingSystem !== defaultParser.options.numberingSystem) {
|
|
53
|
-
let parser = $6c7bd7858deea686$var$getCachedNumberParser(locale + (locale.includes(
|
|
53
|
+
let parser = $6c7bd7858deea686$var$getCachedNumberParser(locale + (locale.includes('-u-') ? '-nu-' : '-u-nu-') + numberingSystem, options);
|
|
54
54
|
if (parser.isValidPartialNumber(value)) return parser;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
return defaultParser;
|
|
58
58
|
}
|
|
59
59
|
function $6c7bd7858deea686$var$getCachedNumberParser(locale, options) {
|
|
60
|
-
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() :
|
|
60
|
+
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() : '');
|
|
61
61
|
let parser = $6c7bd7858deea686$var$numberParserCache.get(cacheKey);
|
|
62
62
|
if (!parser) {
|
|
63
63
|
parser = new $6c7bd7858deea686$var$NumberParserImpl(locale, options);
|
|
@@ -72,58 +72,58 @@ class $6c7bd7858deea686$var$NumberParserImpl {
|
|
|
72
72
|
// to parse the number, we need to remove anything that isn't actually part of the number, for example we want '-10.40' not '-10.40 USD'
|
|
73
73
|
let fullySanitizedValue = this.sanitize(value);
|
|
74
74
|
if (this.symbols.group) // Remove group characters, and replace decimal points and numerals with ASCII values.
|
|
75
|
-
fullySanitizedValue = $6c7bd7858deea686$var$replaceAll(fullySanitizedValue, this.symbols.group,
|
|
76
|
-
if (this.symbols.decimal) fullySanitizedValue = fullySanitizedValue.replace(this.symbols.decimal,
|
|
77
|
-
if (this.symbols.minusSign) fullySanitizedValue = fullySanitizedValue.replace(this.symbols.minusSign,
|
|
75
|
+
fullySanitizedValue = $6c7bd7858deea686$var$replaceAll(fullySanitizedValue, this.symbols.group, '');
|
|
76
|
+
if (this.symbols.decimal) fullySanitizedValue = fullySanitizedValue.replace(this.symbols.decimal, '.');
|
|
77
|
+
if (this.symbols.minusSign) fullySanitizedValue = fullySanitizedValue.replace(this.symbols.minusSign, '-');
|
|
78
78
|
fullySanitizedValue = fullySanitizedValue.replace(this.symbols.numeral, this.symbols.index);
|
|
79
|
-
if (this.options.style ===
|
|
79
|
+
if (this.options.style === 'percent') {
|
|
80
80
|
// javascript is bad at dividing by 100 and maintaining the same significant figures, so perform it on the string before parsing
|
|
81
|
-
let isNegative = fullySanitizedValue.indexOf(
|
|
82
|
-
fullySanitizedValue = fullySanitizedValue.replace(
|
|
83
|
-
let index = fullySanitizedValue.indexOf(
|
|
81
|
+
let isNegative = fullySanitizedValue.indexOf('-');
|
|
82
|
+
fullySanitizedValue = fullySanitizedValue.replace('-', '');
|
|
83
|
+
let index = fullySanitizedValue.indexOf('.');
|
|
84
84
|
if (index === -1) index = fullySanitizedValue.length;
|
|
85
|
-
fullySanitizedValue = fullySanitizedValue.replace(
|
|
85
|
+
fullySanitizedValue = fullySanitizedValue.replace('.', '');
|
|
86
86
|
if (index - 2 === 0) fullySanitizedValue = `0.${fullySanitizedValue}`;
|
|
87
87
|
else if (index - 2 === -1) fullySanitizedValue = `0.0${fullySanitizedValue}`;
|
|
88
|
-
else if (index - 2 === -2) fullySanitizedValue =
|
|
88
|
+
else if (index - 2 === -2) fullySanitizedValue = '0.00';
|
|
89
89
|
else fullySanitizedValue = `${fullySanitizedValue.slice(0, index - 2)}.${fullySanitizedValue.slice(index - 2)}`;
|
|
90
90
|
if (isNegative > -1) fullySanitizedValue = `-${fullySanitizedValue}`;
|
|
91
91
|
}
|
|
92
92
|
let newValue = fullySanitizedValue ? +fullySanitizedValue : NaN;
|
|
93
93
|
if (isNaN(newValue)) return NaN;
|
|
94
|
-
if (this.options.style ===
|
|
94
|
+
if (this.options.style === 'percent') {
|
|
95
95
|
var _this_options_minimumFractionDigits, _this_options_maximumFractionDigits;
|
|
96
96
|
// extra step for rounding percents to what our formatter would output
|
|
97
97
|
let options = {
|
|
98
98
|
...this.options,
|
|
99
|
-
style:
|
|
99
|
+
style: 'decimal',
|
|
100
100
|
minimumFractionDigits: Math.min(((_this_options_minimumFractionDigits = this.options.minimumFractionDigits) !== null && _this_options_minimumFractionDigits !== void 0 ? _this_options_minimumFractionDigits : 0) + 2, 20),
|
|
101
101
|
maximumFractionDigits: Math.min(((_this_options_maximumFractionDigits = this.options.maximumFractionDigits) !== null && _this_options_maximumFractionDigits !== void 0 ? _this_options_maximumFractionDigits : 0) + 2, 20)
|
|
102
102
|
};
|
|
103
103
|
return new $6c7bd7858deea686$export$cd11ab140839f11d(this.locale, options).parse(new (0, $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5)(this.locale, options).format(newValue));
|
|
104
104
|
}
|
|
105
105
|
// accounting will always be stripped to a positive number, so if it's accounting and has a () around everything, then we need to make it negative again
|
|
106
|
-
if (this.options.currencySign ===
|
|
106
|
+
if (this.options.currencySign === 'accounting' && $6c7bd7858deea686$var$CURRENCY_SIGN_REGEX.test(value)) newValue = -1 * newValue;
|
|
107
107
|
return newValue;
|
|
108
108
|
}
|
|
109
109
|
sanitize(value) {
|
|
110
110
|
// Remove literals and whitespace, which are allowed anywhere in the string
|
|
111
|
-
value = value.replace(this.symbols.literals,
|
|
111
|
+
value = value.replace(this.symbols.literals, '');
|
|
112
112
|
// Replace the ASCII minus sign with the minus sign used in the current locale
|
|
113
113
|
// so that both are allowed in case the user's keyboard doesn't have the locale's minus sign.
|
|
114
|
-
if (this.symbols.minusSign) value = value.replace(
|
|
114
|
+
if (this.symbols.minusSign) value = value.replace('-', this.symbols.minusSign);
|
|
115
115
|
// In arab numeral system, their decimal character is 1643, but most keyboards don't type that
|
|
116
116
|
// instead they use the , (44) character or apparently the (1548) character.
|
|
117
|
-
if (this.options.numberingSystem ===
|
|
117
|
+
if (this.options.numberingSystem === 'arab') {
|
|
118
118
|
if (this.symbols.decimal) {
|
|
119
|
-
value = value.replace(
|
|
119
|
+
value = value.replace(',', this.symbols.decimal);
|
|
120
120
|
value = value.replace(String.fromCharCode(1548), this.symbols.decimal);
|
|
121
121
|
}
|
|
122
|
-
if (this.symbols.group) value = $6c7bd7858deea686$var$replaceAll(value,
|
|
122
|
+
if (this.symbols.group) value = $6c7bd7858deea686$var$replaceAll(value, '.', this.symbols.group);
|
|
123
123
|
}
|
|
124
124
|
// fr-FR group character is char code 8239, but that's not a key on the french keyboard,
|
|
125
125
|
// so allow 'period' as a group char and replace it with a space
|
|
126
|
-
if (this.options.locale ===
|
|
126
|
+
if (this.options.locale === 'fr-FR') value = $6c7bd7858deea686$var$replaceAll(value, '.', String.fromCharCode(8239));
|
|
127
127
|
return value;
|
|
128
128
|
}
|
|
129
129
|
isValidPartialNumber(value, minValue = -Infinity, maxValue = Infinity) {
|
|
@@ -136,9 +136,9 @@ class $6c7bd7858deea686$var$NumberParserImpl {
|
|
|
136
136
|
// Numbers that can't have any decimal values fail if a decimal character is typed
|
|
137
137
|
if (this.symbols.decimal && value.indexOf(this.symbols.decimal) > -1 && this.options.maximumFractionDigits === 0) return false;
|
|
138
138
|
// Remove numerals, groups, and decimals
|
|
139
|
-
if (this.symbols.group) value = $6c7bd7858deea686$var$replaceAll(value, this.symbols.group,
|
|
140
|
-
value = value.replace(this.symbols.numeral,
|
|
141
|
-
if (this.symbols.decimal) value = value.replace(this.symbols.decimal,
|
|
139
|
+
if (this.symbols.group) value = $6c7bd7858deea686$var$replaceAll(value, this.symbols.group, '');
|
|
140
|
+
value = value.replace(this.symbols.numeral, '');
|
|
141
|
+
if (this.symbols.decimal) value = value.replace(this.symbols.decimal, '');
|
|
142
142
|
// The number is valid if there are no remaining characters
|
|
143
143
|
return value.length === 0;
|
|
144
144
|
}
|
|
@@ -148,16 +148,16 @@ class $6c7bd7858deea686$var$NumberParserImpl {
|
|
|
148
148
|
this.options = this.formatter.resolvedOptions();
|
|
149
149
|
this.symbols = $6c7bd7858deea686$var$getSymbols(locale, this.formatter, this.options, options);
|
|
150
150
|
var _this_options_minimumFractionDigits, _this_options_maximumFractionDigits;
|
|
151
|
-
if (this.options.style ===
|
|
151
|
+
if (this.options.style === 'percent' && (((_this_options_minimumFractionDigits = this.options.minimumFractionDigits) !== null && _this_options_minimumFractionDigits !== void 0 ? _this_options_minimumFractionDigits : 0) > 18 || ((_this_options_maximumFractionDigits = this.options.maximumFractionDigits) !== null && _this_options_maximumFractionDigits !== void 0 ? _this_options_maximumFractionDigits : 0) > 18)) console.warn('NumberParser cannot handle percentages with greater than 18 decimal places, please reduce the number in your options.');
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
const $6c7bd7858deea686$var$nonLiteralParts = new Set([
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
155
|
+
'decimal',
|
|
156
|
+
'fraction',
|
|
157
|
+
'integer',
|
|
158
|
+
'minusSign',
|
|
159
|
+
'plusSign',
|
|
160
|
+
'group'
|
|
161
161
|
]);
|
|
162
162
|
// This list is derived from https://www.unicode.org/cldr/charts/43/supplemental/language_plural_rules.html#comparison and includes
|
|
163
163
|
// all unique numbers which we need to check in order to determine all the plural forms for a given locale.
|
|
@@ -189,12 +189,12 @@ function $6c7bd7858deea686$var$getSymbols(locale, formatter, intlOptions, origin
|
|
|
189
189
|
let posAllParts = symbolFormatter.formatToParts(10000.111);
|
|
190
190
|
let pluralParts = $6c7bd7858deea686$var$pluralNumbers.map((n)=>symbolFormatter.formatToParts(n));
|
|
191
191
|
var _allParts_find_value;
|
|
192
|
-
let minusSign = (_allParts_find_value = (_allParts_find = allParts.find((p)=>p.type ===
|
|
193
|
-
let plusSign = (_posAllParts_find = posAllParts.find((p)=>p.type ===
|
|
192
|
+
let minusSign = (_allParts_find_value = (_allParts_find = allParts.find((p)=>p.type === 'minusSign')) === null || _allParts_find === void 0 ? void 0 : _allParts_find.value) !== null && _allParts_find_value !== void 0 ? _allParts_find_value : '-';
|
|
193
|
+
let plusSign = (_posAllParts_find = posAllParts.find((p)=>p.type === 'plusSign')) === null || _posAllParts_find === void 0 ? void 0 : _posAllParts_find.value;
|
|
194
194
|
// Safari does not support the signDisplay option, but our number parser polyfills it.
|
|
195
195
|
// If no plus sign was returned, but the original options contained signDisplay, default to the '+' character.
|
|
196
196
|
// @ts-ignore
|
|
197
|
-
if (!plusSign && ((originalOptions === null || originalOptions === void 0 ? void 0 : originalOptions.signDisplay) ===
|
|
197
|
+
if (!plusSign && ((originalOptions === null || originalOptions === void 0 ? void 0 : originalOptions.signDisplay) === 'exceptZero' || (originalOptions === null || originalOptions === void 0 ? void 0 : originalOptions.signDisplay) === 'always')) plusSign = '+';
|
|
198
198
|
// If maximumSignificantDigits is 1 (the minimum) then we won't get decimal characters out of the above formatters
|
|
199
199
|
// Percent also defaults to 0 fractionDigits, so we need to make a new one that isn't percent to get an accurate decimal
|
|
200
200
|
let decimalParts = new Intl.NumberFormat(locale, {
|
|
@@ -202,8 +202,8 @@ function $6c7bd7858deea686$var$getSymbols(locale, formatter, intlOptions, origin
|
|
|
202
202
|
minimumFractionDigits: 2,
|
|
203
203
|
maximumFractionDigits: 2
|
|
204
204
|
}).formatToParts(0.001);
|
|
205
|
-
let decimal = (_decimalParts_find = decimalParts.find((p)=>p.type ===
|
|
206
|
-
let group = (_allParts_find1 = allParts.find((p)=>p.type ===
|
|
205
|
+
let decimal = (_decimalParts_find = decimalParts.find((p)=>p.type === 'decimal')) === null || _decimalParts_find === void 0 ? void 0 : _decimalParts_find.value;
|
|
206
|
+
let group = (_allParts_find1 = allParts.find((p)=>p.type === 'group')) === null || _allParts_find1 === void 0 ? void 0 : _allParts_find1.value;
|
|
207
207
|
// this set is also for a regex, it's all literals that might be in the string we want to eventually parse that
|
|
208
208
|
// don't contribute to the numerical value
|
|
209
209
|
let allPartsLiterals = allParts.filter((p)=>!$6c7bd7858deea686$var$nonLiteralParts.has(p.type)).map((p)=>$6c7bd7858deea686$var$escapeRegex(p.value));
|
|
@@ -214,7 +214,7 @@ function $6c7bd7858deea686$var$getSymbols(locale, formatter, intlOptions, origin
|
|
|
214
214
|
...pluralPartsLiterals
|
|
215
215
|
])
|
|
216
216
|
].sort((a, b)=>b.length - a.length);
|
|
217
|
-
let literals = sortedLiterals.length === 0 ? new RegExp(
|
|
217
|
+
let literals = sortedLiterals.length === 0 ? new RegExp('[\\p{White_Space}]', 'gu') : new RegExp(`${sortedLiterals.join('|')}|[\\p{White_Space}]`, 'gu');
|
|
218
218
|
// These are for replacing non-latn characters with the latn equivalent
|
|
219
219
|
let numerals = [
|
|
220
220
|
...new Intl.NumberFormat(intlOptions.locale, {
|
|
@@ -225,7 +225,7 @@ function $6c7bd7858deea686$var$getSymbols(locale, formatter, intlOptions, origin
|
|
|
225
225
|
d,
|
|
226
226
|
i
|
|
227
227
|
]));
|
|
228
|
-
let numeral = new RegExp(`[${numerals.join(
|
|
228
|
+
let numeral = new RegExp(`[${numerals.join('')}]`, 'g');
|
|
229
229
|
let index = (d)=>String(indexes.get(d));
|
|
230
230
|
return {
|
|
231
231
|
minusSign: minusSign,
|
|
@@ -244,7 +244,7 @@ function $6c7bd7858deea686$var$replaceAll(str, find, replace) {
|
|
|
244
244
|
return str.split(find).join(replace);
|
|
245
245
|
}
|
|
246
246
|
function $6c7bd7858deea686$var$escapeRegex(string) {
|
|
247
|
-
return string.replace(/[.*+?^${}()|[\]\\]/g,
|
|
247
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internationalized/number",
|
|
3
|
-
"version": "3.5.3
|
|
3
|
+
"version": "3.5.3",
|
|
4
4
|
"description": "Internationalized number formatting and parsing utilities",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "b77d7d594dff4dcfb5359bffbcfd18142b146433"
|
|
31
31
|
}
|