@aemforms/af-formatters 0.22.30 → 0.22.32
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/lib/date/DateParser.js +530 -0
- package/lib/date/SkeletonParser.js +319 -0
- package/lib/date/index.js +27 -0
- package/lib/index.js +103 -0
- package/lib/number/NumberParser.js +128 -0
- package/lib/number/SkeletonParser.js +236 -0
- package/lib/{esm/number → number}/currencies.js +14 -5
- package/package.json +5 -9
- package/lib/cjs/index.cjs +0 -781
- package/lib/esm/date/DateParser.js +0 -320
- package/lib/esm/date/SkeletonParser.js +0 -199
- package/lib/esm/date/index.js +0 -22
- package/lib/esm/index.js +0 -57
- package/lib/esm/number/NumberParser.js +0 -100
- package/lib/esm/number/SkeletonParser.js +0 -173
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ShorthandStyles = void 0;
|
|
7
|
+
exports.parseNumberSkeleton = parseNumberSkeleton;
|
|
8
|
+
|
|
9
|
+
var _currencies = require("./currencies.js");
|
|
10
|
+
|
|
11
|
+
/*************************************************************************
|
|
12
|
+
* ADOBE CONFIDENTIAL
|
|
13
|
+
* ___________________
|
|
14
|
+
*
|
|
15
|
+
* Copyright 2022 Adobe
|
|
16
|
+
* All Rights Reserved.
|
|
17
|
+
*
|
|
18
|
+
* NOTICE: All information contained herein is, and remains
|
|
19
|
+
* the property of Adobe and its suppliers, if any. The intellectual
|
|
20
|
+
* and technical concepts contained herein are proprietary to Adobe
|
|
21
|
+
* and its suppliers and are protected by all applicable intellectual
|
|
22
|
+
* property laws, including trade secret and copyright laws.
|
|
23
|
+
* Dissemination of this information or reproduction of this material
|
|
24
|
+
* is strictly forbidden unless prior written permission is obtained
|
|
25
|
+
* from Adobe.
|
|
26
|
+
|
|
27
|
+
* Adobe permits you to use and modify this file solely in accordance with
|
|
28
|
+
* the terms of the Adobe license agreement accompanying it.
|
|
29
|
+
*************************************************************************/
|
|
30
|
+
const NUMBER_REGEX = // eslint-disable-next-line max-len
|
|
31
|
+
/(?:[#]+|[@]+(#+)?|[0]+|[,]|[.]|[-]|[+]|[%]|[¤]{1,4}(?:\/([a-zA-Z]{3}))?|[;]|[K]{1,2}|E{1,2}[+]?|'(?:[^']|'')*')|[^a-zA-Z']+/g;
|
|
32
|
+
const options = {
|
|
33
|
+
compactDisplay: ['short', 'long'],
|
|
34
|
+
//valid only when notation is compact
|
|
35
|
+
currency: '',
|
|
36
|
+
// must be provided if the style is currency
|
|
37
|
+
currencyDisplay: ["symbol", 'narrowSymbol', 'code', 'name'],
|
|
38
|
+
currencySign: ['accounting', 'standard'],
|
|
39
|
+
localeMatcher: ['lookup', 'best fit'],
|
|
40
|
+
notation: ['standard', 'scientific', 'engineering', 'compact'],
|
|
41
|
+
numberingSystem: '',
|
|
42
|
+
signDisplay: ['auto', 'always', 'exceptZero', 'negative', 'never'],
|
|
43
|
+
style: ['decimal', 'currency', 'percent', 'unit'],
|
|
44
|
+
unit: '',
|
|
45
|
+
//https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-issanctionedsimpleunitidentifier
|
|
46
|
+
unitDisplay: ['long', 'short', 'narrow'],
|
|
47
|
+
useGrouping: ['always', 'auto', 'min2', false, true],
|
|
48
|
+
roundingMode: '',
|
|
49
|
+
roundingPriority: '',
|
|
50
|
+
roundingIncrement: '',
|
|
51
|
+
trailingZeroDisplay: ['auto', 'stripIfInteger'],
|
|
52
|
+
minimumIntegerDigits: '',
|
|
53
|
+
minimumFractionDigits: '',
|
|
54
|
+
maximumFractionDigits: '',
|
|
55
|
+
minimumSignificantDigits: '',
|
|
56
|
+
maximumSignificantDigits: ''
|
|
57
|
+
};
|
|
58
|
+
const supportedUnits = ['acre', 'bit', 'byte', 'celsius', 'centimeter', 'day', 'degree', 'fahrenheit', 'fluid-ounce', 'foot', 'gallon', 'gigabit', 'gigabyte', 'gram', 'hectare', 'hour', 'inch', 'kilobit', 'kilobyte', 'kilogram', 'kilometer', 'liter', 'megabit', 'megabyte', 'meter', 'mile', 'mile-scandinavian', 'milliliter', 'millimeter', 'millisecond', 'minute', 'month', 'ounce', 'percent', 'petabyte', 'pound', 'second', 'stone', 'terabit', 'terabyte', 'week', 'yard', 'year'].join('|');
|
|
59
|
+
const ShorthandStyles = [/^currency(?:\/([a-zA-Z]{3}))?$/, /^decimal$/, /^integer$/, /^percent$/, new RegExp(`^unit\/(${supportedUnits})$`)];
|
|
60
|
+
exports.ShorthandStyles = ShorthandStyles;
|
|
61
|
+
|
|
62
|
+
function parseNumberSkeleton(skeleton, language) {
|
|
63
|
+
const options = {};
|
|
64
|
+
const order = [];
|
|
65
|
+
let match, index;
|
|
66
|
+
|
|
67
|
+
for (index = 0; index < ShorthandStyles.length && match == null; index++) {
|
|
68
|
+
match = ShorthandStyles[index].exec(skeleton);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (match) {
|
|
72
|
+
switch (index) {
|
|
73
|
+
case 1:
|
|
74
|
+
options.style = 'currency';
|
|
75
|
+
options.currencyDisplay = 'narrowSymbol';
|
|
76
|
+
|
|
77
|
+
if (match[1]) {
|
|
78
|
+
options.currency = match[1];
|
|
79
|
+
} else {
|
|
80
|
+
options.currency = (0, _currencies.getCurrency)(language);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
break;
|
|
84
|
+
|
|
85
|
+
case 2:
|
|
86
|
+
const defaultOptions = new Intl.NumberFormat(language, {}).resolvedOptions();
|
|
87
|
+
options.minimumFractionDigits = options.minimumFractionDigits || 2;
|
|
88
|
+
break;
|
|
89
|
+
|
|
90
|
+
case 3:
|
|
91
|
+
options.minimumFractionDigits = 0;
|
|
92
|
+
options.maximumFractionDigits = 0;
|
|
93
|
+
break;
|
|
94
|
+
|
|
95
|
+
case 4:
|
|
96
|
+
options.style = 'percent';
|
|
97
|
+
options.maximumFractionDigits = 2;
|
|
98
|
+
break;
|
|
99
|
+
|
|
100
|
+
case 5:
|
|
101
|
+
options.style = "unit";
|
|
102
|
+
options.unitDisplay = "long";
|
|
103
|
+
options.unit = match[1];
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
options,
|
|
109
|
+
order
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
options.useGrouping = false;
|
|
114
|
+
options.minimumIntegerDigits = 1;
|
|
115
|
+
options.maximumFractionDigits = 0;
|
|
116
|
+
options.minimumFractionDigits = 0;
|
|
117
|
+
skeleton.replace(NUMBER_REGEX, (match, maxSignificantDigits, currencySymbol, offset) => {
|
|
118
|
+
const len = match.length;
|
|
119
|
+
|
|
120
|
+
switch (match[0]) {
|
|
121
|
+
case '#':
|
|
122
|
+
order.push(['digit', len]);
|
|
123
|
+
|
|
124
|
+
if ((options === null || options === void 0 ? void 0 : options.decimal) === true) {
|
|
125
|
+
options.maximumFractionDigits = options.minimumFractionDigits + len;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
break;
|
|
129
|
+
|
|
130
|
+
case '@':
|
|
131
|
+
if (options !== null && options !== void 0 && options.minimumSignificantDigits) {
|
|
132
|
+
throw "@ symbol should occur together";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const hashes = maxSignificantDigits || "";
|
|
136
|
+
order.push(['@', len - hashes.length]);
|
|
137
|
+
options.minimumSignificantDigits = len - hashes.length;
|
|
138
|
+
options.maximumSignificantDigits = len;
|
|
139
|
+
order.push(['digit', hashes.length]);
|
|
140
|
+
break;
|
|
141
|
+
|
|
142
|
+
case ',':
|
|
143
|
+
if ((options === null || options === void 0 ? void 0 : options.decimal) === true) {
|
|
144
|
+
throw "grouping character not supporting for fractions";
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
order.push(['group', 1]);
|
|
148
|
+
options.useGrouping = 'auto';
|
|
149
|
+
break;
|
|
150
|
+
|
|
151
|
+
case '.':
|
|
152
|
+
if (options !== null && options !== void 0 && options.decimal) {
|
|
153
|
+
console.error("only one decimal symbol is allowed");
|
|
154
|
+
} else {
|
|
155
|
+
order.push(['decimal', 1]);
|
|
156
|
+
options.decimal = true;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
break;
|
|
160
|
+
|
|
161
|
+
case '0':
|
|
162
|
+
order.push('0', len);
|
|
163
|
+
|
|
164
|
+
if (options.minimumSignificantDigits || options.maximumSignificantDigits) {
|
|
165
|
+
throw "0 is not supported with @";
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if ((options === null || options === void 0 ? void 0 : options.decimal) === true) {
|
|
169
|
+
options.minimumFractionDigits = len;
|
|
170
|
+
|
|
171
|
+
if (!options.maximumFractionDigits) {
|
|
172
|
+
options.maximumFractionDigits = len;
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
options.minimumIntegerDigits = len;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
break;
|
|
179
|
+
|
|
180
|
+
case '-':
|
|
181
|
+
if (offset !== 0) {
|
|
182
|
+
console.error("sign display is always in the beginning");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
options.signDisplay = 'negative';
|
|
186
|
+
order.push(['signDisplay', 1, '-']);
|
|
187
|
+
break;
|
|
188
|
+
|
|
189
|
+
case '+':
|
|
190
|
+
if (offset !== 0 && order[order.length - 1][0] === 'E') {
|
|
191
|
+
console.error("sign display is always in the beginning");
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (offset === 0) {
|
|
195
|
+
options.signDisplay = 'always';
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
order.push(['signDisplay', 1, '+']);
|
|
199
|
+
break;
|
|
200
|
+
|
|
201
|
+
case '¤':
|
|
202
|
+
if (offset !== 0 && offset !== skeleton.length - 1) {
|
|
203
|
+
console.error("currency display should be either in the beginning or at the end");
|
|
204
|
+
} else {
|
|
205
|
+
options.style = 'currency';
|
|
206
|
+
options.currencyDisplay = ['symbol', 'code', 'name', 'narrowSymbol'][len - 1];
|
|
207
|
+
options.currency = currencySymbol || (0, _currencies.getCurrency)(language);
|
|
208
|
+
order.push(['currency', len]);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
break;
|
|
212
|
+
|
|
213
|
+
case '%':
|
|
214
|
+
if (offset !== 0 && offset !== skeleton.length - 1) {
|
|
215
|
+
console.error("percent display should be either in the beginning or at the end");
|
|
216
|
+
} else {
|
|
217
|
+
order.push(['%', 1]);
|
|
218
|
+
options.style = 'percent';
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
break;
|
|
222
|
+
|
|
223
|
+
case 'E':
|
|
224
|
+
order.push(['E', len]);
|
|
225
|
+
options.style = ['scientific', 'engineering'](len - 1);
|
|
226
|
+
break;
|
|
227
|
+
|
|
228
|
+
default:
|
|
229
|
+
console.error("unknown chars" + match);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
return {
|
|
233
|
+
options,
|
|
234
|
+
order
|
|
235
|
+
};
|
|
236
|
+
}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getCurrency = void 0;
|
|
7
|
+
|
|
1
8
|
/*************************************************************************
|
|
2
9
|
* ADOBE CONFIDENTIAL
|
|
3
10
|
* ___________________
|
|
@@ -17,7 +24,6 @@
|
|
|
17
24
|
* Adobe permits you to use and modify this file solely in accordance with
|
|
18
25
|
* the terms of the Adobe license agreement accompanying it.
|
|
19
26
|
*************************************************************************/
|
|
20
|
-
|
|
21
27
|
const currencies = {
|
|
22
28
|
'da-DK': 'DKK',
|
|
23
29
|
'de-DE': 'EUR',
|
|
@@ -41,16 +47,19 @@ const currencies = {
|
|
|
41
47
|
'tr-TR': 'TRY'
|
|
42
48
|
};
|
|
43
49
|
const locales = Object.keys(currencies);
|
|
50
|
+
|
|
44
51
|
const getCurrency = function (locale) {
|
|
45
52
|
if (locales.indexOf(locale) > -1) {
|
|
46
|
-
return currencies[locale]
|
|
53
|
+
return currencies[locale];
|
|
47
54
|
} else {
|
|
48
55
|
const matchingLocale = locales.find(x => x.startsWith(locale));
|
|
56
|
+
|
|
49
57
|
if (matchingLocale) {
|
|
50
|
-
return currencies[matchingLocale]
|
|
58
|
+
return currencies[matchingLocale];
|
|
51
59
|
}
|
|
52
60
|
}
|
|
53
|
-
|
|
61
|
+
|
|
62
|
+
return '';
|
|
54
63
|
};
|
|
55
64
|
|
|
56
|
-
|
|
65
|
+
exports.getCurrency = getCurrency;
|
package/package.json
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-formatters",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.32",
|
|
4
4
|
"description": "Formatting Module for Forms Runtime",
|
|
5
5
|
"author": "Adobe Systems",
|
|
6
6
|
"license": "Adobe Proprietary",
|
|
7
|
-
"main": "lib/
|
|
7
|
+
"main": "lib/index.js",
|
|
8
8
|
"directories": {
|
|
9
9
|
"lib": "lib",
|
|
10
10
|
"source": "src",
|
|
11
11
|
"test": "src/__tests__"
|
|
12
12
|
},
|
|
13
|
-
"type": "module",
|
|
14
|
-
"exports": {
|
|
15
|
-
".": "./lib/esm/index.js"
|
|
16
|
-
},
|
|
17
13
|
"publishConfig": {
|
|
18
14
|
"access": "public"
|
|
19
15
|
},
|
|
@@ -28,11 +24,11 @@
|
|
|
28
24
|
"LICENSE"
|
|
29
25
|
],
|
|
30
26
|
"scripts": {
|
|
31
|
-
"test": "
|
|
27
|
+
"test": "jest --silent",
|
|
32
28
|
"eslint": "npx eslint src/**",
|
|
33
29
|
"eslint:fix": "npx eslint --fix src/**",
|
|
34
|
-
"test:ci": "
|
|
35
|
-
"build": "
|
|
30
|
+
"test:ci": "jest --silent --coverage",
|
|
31
|
+
"build": "babel src -d lib",
|
|
36
32
|
"clean": "rm -rf lib target",
|
|
37
33
|
"prepublishOnly": "npm run build && npm run test",
|
|
38
34
|
"docs": "npx typedoc --options .typedoc.cjs"
|