@aemforms/af-formatters 0.22.18 → 0.22.20

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.
@@ -1,315 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getSkeleton = getSkeleton;
7
- exports.parseDateTimeSkeleton = parseDateTimeSkeleton;
8
-
9
- var _DateParser = require("./DateParser");
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
-
28
- /**
29
- * https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
30
- * Credit: https://git.corp.adobe.com/dc/dfl/blob/master/src/patterns/parseDateTimeSkeleton.js
31
- * Created a separate library to be used elsewhere as well.
32
- */
33
- const DATE_TIME_REGEX = // eslint-disable-next-line max-len
34
- /(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvV]{1,5}|[zZOvVxX]{1,3}|S{1,3}|'(?:[^']|'')*')|[^a-zA-Z']+/g;
35
- const testDate = new Date(2000, 2, 1, 2, 3, 4);
36
- /**
37
- * Since the formatted month names are different than standalone month names, we need to identify the correct option
38
- * to pass for formatting
39
- * @param value {string} formatted value of the month
40
- * @param language {string} language in which the month is formatted
41
- * @param isMediumFormatStyle {boolean} if shorthand style used for formatting was medium
42
- */
43
-
44
- function deduceMonthOption(value, language, isMediumFormatStyle) {
45
- const formattedMarch = value;
46
- const longMarch = new Intl.DateTimeFormat(language, {
47
- month: 'long'
48
- }).formatToParts(testDate)[0].value;
49
- const shortMarch = new Intl.DateTimeFormat(language, {
50
- month: 'short'
51
- }).formatToParts(testDate)[0].value;
52
- const monthOptions = {
53
- [longMarch]: 'long',
54
- [shortMarch]: 'short',
55
- '03': '2-digit',
56
- '3': 'numeric'
57
- };
58
-
59
- if (formattedMarch !== undefined) {
60
- monthOptions[formattedMarch] = isMediumFormatStyle ? 'short' : 'long';
61
- }
62
-
63
- return monthOptions[value];
64
- }
65
-
66
- function getSkeleton(skeleton, language) {
67
- if (_DateParser.ShorthandStyles.find(type => skeleton.includes(type))) {
68
- const parsed = parseDateStyle(skeleton, language);
69
- const result = [];
70
- const symbols = {
71
- month: 'M',
72
- year: 'Y',
73
- day: 'd'
74
- };
75
- parsed.forEach(_ref => {
76
- let [type, option, length] = _ref;
77
-
78
- if (type in symbols) {
79
- result.push(Array(length).fill(symbols[type]).join(''));
80
- } else if (type === 'literal') {
81
- result.push(option);
82
- }
83
- });
84
- return result.join('');
85
- }
86
-
87
- return skeleton;
88
- }
89
- /**
90
- *
91
- * @param skeleton shorthand style for the date concatenated with shorthand style of time. The
92
- * Shorthand style for both date and time is one of ['full', 'long', 'medium', 'short'].
93
- * @param language {string} language to parse the date shorthand style
94
- * @returns {[*,string][]}
95
- */
96
-
97
-
98
- function parseDateStyle(skeleton, language) {
99
- const options = {}; // the skeleton could have two keywords -- one for date, one for time
100
-
101
- const styles = skeleton.split(/\s/).filter(s => s.length);
102
- options.dateStyle = styles[0];
103
- if (styles.length > 1) options.timeStyle = styles[1];
104
- const testDate = new Date(2000, 2, 1, 2, 3, 4);
105
- const parts = new Intl.DateTimeFormat(language, options).formatToParts(testDate); // oddly, the formatted month name can be different from the standalone month name
106
-
107
- const formattedMarch = parts.find(p => p.type === 'month').value;
108
- const longMarch = new Intl.DateTimeFormat(language, {
109
- month: 'long'
110
- }).formatToParts(testDate)[0].value;
111
- const shortMarch = new Intl.DateTimeFormat(language, {
112
- month: 'short'
113
- }).formatToParts(testDate)[0].value;
114
- const result = [];
115
- parts.forEach(_ref2 => {
116
- let {
117
- type,
118
- value
119
- } = _ref2;
120
- let option;
121
-
122
- if (type === 'month') {
123
- option = {
124
- [formattedMarch]: skeleton === 'medium' ? 'short' : 'long',
125
- [longMarch]: 'long',
126
- [shortMarch]: 'short',
127
- '03': '2-digit',
128
- '3': 'numeric'
129
- }[value];
130
- }
131
-
132
- if (type === 'year') option = {
133
- '2000': 'numeric',
134
- '00': '2-digit'
135
- }[value];
136
- if (['day', 'hour', 'minute', 'second'].includes(type)) option = value.length === 2 ? '2-digit' : 'numeric';
137
- if (type === 'literal') option = value;
138
- if (type === 'dayPeriod') option = 'short';
139
- result.push([type, option, value.length]);
140
- });
141
- return result;
142
- }
143
- /**
144
- * Parse Date time skeleton into Intl.DateTimeFormatOptions parts
145
- * Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
146
- */
147
-
148
-
149
- function parseDateTimeSkeleton(skeleton, language) {
150
- if (_DateParser.ShorthandStyles.find(type => skeleton.includes(type))) {
151
- return parseDateStyle(skeleton, language);
152
- }
153
-
154
- const result = [];
155
- skeleton.replace(DATE_TIME_REGEX, match => {
156
- const len = match.length;
157
-
158
- switch (match[0]) {
159
- // Era
160
- case 'G':
161
- result.push(['era', len === 4 ? 'long' : len === 5 ? 'narrow' : 'short', len]);
162
- break;
163
- // Year
164
-
165
- case 'y':
166
- result.push(['year', len === 2 ? '2-digit' : 'numeric', len]);
167
- break;
168
-
169
- case 'Y':
170
- case 'u':
171
- case 'U':
172
- case 'r':
173
- throw new RangeError('`Y/u/U/r` (year) patterns are not supported, use `y` instead');
174
- // Quarter
175
-
176
- case 'q':
177
- case 'Q':
178
- throw new RangeError('`q/Q` (quarter) patterns are not supported');
179
- // Month
180
-
181
- case 'M':
182
- case 'L':
183
- result.push(['month', ['numeric', '2-digit', 'short', 'long', 'narrow'][len - 1], len]);
184
- break;
185
- // Week
186
-
187
- case 'w':
188
- case 'W':
189
- throw new RangeError('`w/W` (week) patterns are not supported');
190
-
191
- case 'd':
192
- result.push(['day', ['numeric', '2-digit'][len - 1], len]);
193
- break;
194
-
195
- case 'D':
196
- case 'F':
197
- case 'g':
198
- throw new RangeError('`D/F/g` (day) patterns are not supported, use `d` instead');
199
- // Weekday
200
-
201
- case 'E':
202
- result.push(['weekday', ['short', 'short', 'short', 'long', 'narrow', 'narrow'][len - 1], len]);
203
- break;
204
-
205
- case 'e':
206
- if (len < 4) {
207
- throw new RangeError('`e..eee` (weekday) patterns are not supported');
208
- }
209
-
210
- result.push(['weekday', ['short', 'long', 'narrow', 'short'][len - 4], len]);
211
- break;
212
-
213
- case 'c':
214
- if (len < 3 || len > 5) {
215
- throw new RangeError('`c, cc, cccccc` (weekday) patterns are not supported');
216
- }
217
-
218
- result.push(['weekday', ['short', 'long', 'narrow', 'short'][len - 3], len]);
219
- break;
220
- // Period
221
-
222
- case 'a':
223
- // AM, PM
224
- result.push(['hour12', true, 1]);
225
- break;
226
-
227
- case 'b': // am, pm, noon, midnight
228
-
229
- case 'B':
230
- // flexible day periods
231
- throw new RangeError('`b/B` (period) patterns are not supported, use `a` instead');
232
- // Hour
233
-
234
- case 'h':
235
- result.push(['hourCycle', 'h12']);
236
- result.push(['hour', ['numeric', '2-digit'][len - 1], len]);
237
- break;
238
-
239
- case 'H':
240
- result.push(['hourCycle', 'h23', 1]);
241
- result.push(['hour', ['numeric', '2-digit'][len - 1], len]);
242
- break;
243
-
244
- case 'K':
245
- result.push(['hourCycle', 'h11', 1]);
246
- result.push(['hour', ['numeric', '2-digit'][len - 1], len]);
247
- break;
248
-
249
- case 'k':
250
- result.push(['hourCycle', 'h24', 1]);
251
- result.push(['hour', ['numeric', '2-digit'][len - 1], len]);
252
- break;
253
-
254
- case 'j':
255
- case 'J':
256
- case 'C':
257
- throw new RangeError('`j/J/C` (hour) patterns are not supported, use `h/H/K/k` instead');
258
- // Minute
259
-
260
- case 'm':
261
- result.push(['minute', ['numeric', '2-digit'][len - 1], len]);
262
- break;
263
- // Second
264
-
265
- case 's':
266
- result.push(['second', ['numeric', '2-digit'][len - 1], len]);
267
- break;
268
-
269
- case 'S':
270
- result.push(['fractionalSecondDigits', len, len]);
271
- break;
272
-
273
- case 'A':
274
- throw new RangeError('`S/A` (millisecond) patterns are not supported, use `s` instead');
275
- // Zone
276
-
277
- case 'O':
278
- // timeZone GMT-8 or GMT-08:00
279
- result.push(['timeZoneName', len < 4 ? 'shortOffset' : 'longOffset', len]);
280
- result.push(['x-timeZoneName', len < 4 ? 'O' : 'OOOO', len]);
281
- break;
282
-
283
- case 'X': // 1, 2, 3, 4: The ISO8601 varios formats
284
-
285
- case 'x': // 1, 2, 3, 4: The ISO8601 varios formats
286
-
287
- case 'Z':
288
- // 1..3, 4, 5: The ISO8601 varios formats
289
- // Z, ZZ, ZZZ should produce -0800
290
- // ZZZZ should produce GMT-08:00
291
- // ZZZZZ should produce -8:00 or -07:52:58
292
- result.push(['timeZoneName', 'longOffset', 1]);
293
- result.push(['x-timeZoneName', match, 1]);
294
- break;
295
-
296
- case 'z': // 1..3, 4: specific non-location format
297
-
298
- case 'v': // 1, 4: generic non-location format
299
-
300
- case 'V':
301
- // 1, 2, 3, 4: time zone ID or city
302
- throw new RangeError('z/v/V` (timeZone) patterns are not supported, use `X/x/Z/O` instead');
303
-
304
- case '\'':
305
- result.push(['literal', match.slice(1, -1).replace(/''/g, '\''), -1]);
306
- break;
307
-
308
- default:
309
- result.push(['literal', match, -1]);
310
- }
311
-
312
- return '';
313
- });
314
- return result;
315
- }
package/lib/date/index.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "formatDate", {
7
- enumerable: true,
8
- get: function () {
9
- return _DateParser.formatDate;
10
- }
11
- });
12
- Object.defineProperty(exports, "getSkeleton", {
13
- enumerable: true,
14
- get: function () {
15
- return _SkeletonParser.getSkeleton;
16
- }
17
- });
18
- Object.defineProperty(exports, "parseDate", {
19
- enumerable: true,
20
- get: function () {
21
- return _DateParser.parseDate;
22
- }
23
- });
24
-
25
- var _DateParser = require("./DateParser");
26
-
27
- var _SkeletonParser = require("./SkeletonParser");
package/lib/index.js DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "formatDate", {
7
- enumerable: true,
8
- get: function () {
9
- return _date.formatDate;
10
- }
11
- });
12
- Object.defineProperty(exports, "getSkeleton", {
13
- enumerable: true,
14
- get: function () {
15
- return _date.getSkeleton;
16
- }
17
- });
18
- Object.defineProperty(exports, "parseDate", {
19
- enumerable: true,
20
- get: function () {
21
- return _date.parseDate;
22
- }
23
- });
24
-
25
- var _date = require("./date");