atomic-fns 1.1.7 → 2.0.0
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/README.md +405 -60
- package/dist/array/index.d.ts +9 -0
- package/dist/array/index.js +9 -0
- package/dist/array/list.d.ts +99 -0
- package/dist/array/list.js +133 -0
- package/dist/array/sets.d.ts +130 -0
- package/dist/array/sets.js +213 -0
- package/dist/async/index.d.ts +6 -0
- package/dist/async/index.js +6 -0
- package/dist/async/retry.d.ts +38 -0
- package/dist/async/retry.js +56 -0
- package/dist/async/sleep.d.ts +42 -0
- package/dist/async/sleep.js +76 -0
- package/dist/collections/bisect.d.ts +103 -0
- package/dist/collections/bisect.js +157 -0
- package/dist/collections/deque.d.ts +67 -97
- package/dist/collections/deque.js +197 -249
- package/dist/collections/entries.d.ts +89 -0
- package/dist/collections/entries.js +131 -0
- package/dist/collections/frozen-set.d.ts +42 -0
- package/dist/collections/frozen-set.js +64 -0
- package/dist/collections/group.d.ts +141 -0
- package/dist/collections/group.js +241 -0
- package/dist/collections/heap.d.ts +64 -0
- package/dist/collections/heap.js +205 -0
- package/dist/collections/index.d.ts +15 -642
- package/dist/collections/index.js +14 -716
- package/dist/collections/internal/arrayKeys.d.ts +19 -0
- package/dist/collections/internal/arrayKeys.js +83 -0
- package/dist/collections/internal/invariants.d.ts +4 -0
- package/dist/collections/internal/invariants.js +12 -0
- package/dist/collections/internal/iterable.d.ts +25 -0
- package/dist/collections/internal/iterable.js +62 -0
- package/dist/collections/iterate.d.ts +162 -0
- package/dist/collections/iterate.js +188 -0
- package/dist/collections/lru-cache.d.ts +58 -0
- package/dist/collections/lru-cache.js +164 -0
- package/dist/collections/order.d.ts +19 -0
- package/dist/collections/order.js +38 -0
- package/dist/collections/shape.d.ts +32 -0
- package/dist/collections/shape.js +86 -0
- package/dist/collections/sorted-map.d.ts +171 -0
- package/dist/collections/sorted-map.js +845 -0
- package/dist/collections/sorted-set.d.ts +103 -0
- package/dist/collections/sorted-set.js +147 -0
- package/dist/collections/splay-tree.d.ts +82 -0
- package/dist/collections/splay-tree.js +354 -0
- package/dist/collections/trie.d.ts +58 -0
- package/dist/collections/trie.js +196 -0
- package/dist/decimal/currency.d.ts +211 -0
- package/dist/decimal/currency.js +321 -0
- package/dist/decimal/decimal.d.ts +299 -0
- package/dist/decimal/decimal.js +660 -0
- package/dist/decimal/index.d.ts +11 -145
- package/dist/decimal/index.js +10 -374
- package/dist/decimal/internal/bits.d.ts +2 -0
- package/dist/decimal/internal/bits.js +7 -0
- package/dist/decimal/internal/echo.d.ts +4 -0
- package/dist/decimal/internal/echo.js +6 -0
- package/dist/decimal/internal/isqrt.d.ts +9 -0
- package/dist/decimal/internal/isqrt.js +34 -0
- package/dist/decimal/internal/locale.d.ts +7 -0
- package/dist/decimal/internal/locale.js +24 -0
- package/dist/decimal/internal/minor-units.d.ts +2 -0
- package/dist/decimal/internal/minor-units.js +33 -0
- package/dist/decimal/internal/pow10.d.ts +24 -0
- package/dist/decimal/internal/pow10.js +96 -0
- package/dist/encoding/base64.d.ts +39 -0
- package/dist/encoding/base64.js +53 -0
- package/dist/encoding/hex.d.ts +23 -0
- package/dist/encoding/hex.js +34 -0
- package/dist/encoding/index.d.ts +6 -0
- package/dist/encoding/index.js +6 -0
- package/dist/function/debounce.d.ts +68 -0
- package/dist/function/debounce.js +203 -0
- package/dist/function/index.d.ts +6 -0
- package/dist/function/index.js +6 -0
- package/dist/function/shared.d.ts +2 -0
- package/dist/function/shared.js +5 -0
- package/dist/function/wrap.d.ts +130 -0
- package/dist/function/wrap.js +113 -0
- package/dist/hash/digest.d.ts +18 -0
- package/dist/hash/digest.js +26 -0
- package/dist/hash/hash.d.ts +22 -0
- package/dist/hash/hash.js +252 -0
- package/dist/hash/hashString.d.ts +13 -0
- package/dist/hash/hashString.js +53 -0
- package/dist/hash/index.d.ts +8 -0
- package/dist/hash/index.js +8 -0
- package/dist/hash/stableStringify.d.ts +19 -0
- package/dist/hash/stableStringify.js +102 -0
- package/dist/id/index.d.ts +7 -0
- package/dist/id/index.js +7 -0
- package/dist/id/nanoid.d.ts +16 -0
- package/dist/id/nanoid.js +65 -0
- package/dist/id/uniqueId.d.ts +14 -0
- package/dist/id/uniqueId.js +20 -0
- package/dist/id/uuid.d.ts +25 -0
- package/dist/id/uuid.js +64 -0
- package/dist/index.d.ts +15 -8
- package/dist/index.js +15 -8
- package/dist/internal/bytes.d.ts +11 -0
- package/dist/internal/bytes.js +33 -0
- package/dist/internal/codec.d.ts +11 -0
- package/dist/internal/codec.js +84 -0
- package/dist/internal/compare.d.ts +10 -0
- package/dist/internal/compare.js +26 -0
- package/dist/internal/crypto.d.ts +5 -0
- package/dist/internal/crypto.js +11 -0
- package/dist/internal/keys.d.ts +12 -0
- package/dist/internal/keys.js +23 -0
- package/dist/internal/kind.d.ts +44 -0
- package/dist/internal/kind.js +139 -0
- package/dist/internal/sparse.d.ts +51 -0
- package/dist/internal/sparse.js +104 -0
- package/dist/internal/text.d.ts +7 -0
- package/dist/internal/text.js +15 -0
- package/dist/internal/timer.d.ts +10 -0
- package/dist/internal/timer.js +17 -0
- package/dist/internal/truncate.d.ts +10 -0
- package/dist/internal/truncate.js +22 -0
- package/dist/internal/walk.d.ts +47 -0
- package/dist/internal/walk.js +100 -0
- package/dist/is/index.d.ts +8 -0
- package/dist/is/index.js +8 -0
- package/dist/is/isArrayLike.d.ts +18 -0
- package/dist/is/isArrayLike.js +25 -0
- package/dist/is/isError.d.ts +13 -0
- package/dist/is/isError.js +18 -0
- package/dist/is/isNil.d.ts +12 -0
- package/dist/is/isNil.js +14 -0
- package/dist/is/isPlainObject.d.ts +15 -0
- package/dist/is/isPlainObject.js +34 -0
- package/dist/number/index.d.ts +7 -0
- package/dist/number/index.js +7 -0
- package/dist/number/round.d.ts +86 -0
- package/dist/number/round.js +130 -0
- package/dist/number/stats.d.ts +52 -0
- package/dist/number/stats.js +115 -0
- package/dist/object/cloneDeep.d.ts +28 -0
- package/dist/object/cloneDeep.js +200 -0
- package/dist/object/index.d.ts +14 -0
- package/dist/object/index.js +13 -0
- package/dist/object/isEqual.d.ts +64 -0
- package/dist/object/isEqual.js +289 -0
- package/dist/object/matches.d.ts +40 -0
- package/dist/object/matches.js +284 -0
- package/dist/object/merge.d.ts +66 -0
- package/dist/object/merge.js +272 -0
- package/dist/object/parsePath.d.ts +22 -0
- package/dist/object/parsePath.js +111 -0
- package/dist/object/path.d.ts +85 -0
- package/dist/object/path.js +208 -0
- package/dist/object/pick.d.ts +91 -0
- package/dist/object/pick.js +180 -0
- package/dist/object/reshape.d.ts +73 -0
- package/dist/object/reshape.js +144 -0
- package/dist/random/index.d.ts +96 -32
- package/dist/random/index.js +215 -50
- package/dist/string/case.d.ts +71 -0
- package/dist/string/case.js +152 -0
- package/dist/string/fold.d.ts +35 -0
- package/dist/string/fold.js +100 -0
- package/dist/string/index.d.ts +6 -187
- package/dist/string/index.js +6 -226
- package/dist/string/truncate.d.ts +25 -0
- package/dist/string/truncate.js +44 -0
- package/dist/string/words.d.ts +27 -0
- package/dist/string/words.js +241 -0
- package/package.json +101 -58
- package/dist/collections/BTree.d.ts +0 -229
- package/dist/collections/BTree.js +0 -1165
- package/dist/collections/Heap.d.ts +0 -69
- package/dist/collections/Heap.js +0 -181
- package/dist/collections/LRUCache.d.ts +0 -80
- package/dist/collections/LRUCache.js +0 -126
- package/dist/collections/SortedMap.d.ts +0 -92
- package/dist/collections/SortedMap.js +0 -131
- package/dist/collections/SortedSet.d.ts +0 -69
- package/dist/collections/SortedSet.js +0 -99
- package/dist/collections/SortedTree.d.ts +0 -103
- package/dist/collections/SortedTree.js +0 -141
- package/dist/collections/SplayTree.d.ts +0 -105
- package/dist/collections/SplayTree.js +0 -338
- package/dist/collections/Trie.d.ts +0 -42
- package/dist/collections/Trie.js +0 -104
- package/dist/collections/abc.d.ts +0 -152
- package/dist/collections/abc.js +0 -39
- package/dist/collections/frozenset.d.ts +0 -19
- package/dist/collections/frozenset.js +0 -30
- package/dist/functools/index.d.ts +0 -130
- package/dist/functools/index.js +0 -235
- package/dist/globals/index.d.ts +0 -285
- package/dist/globals/index.js +0 -463
- package/dist/i18n/currency.d.ts +0 -24
- package/dist/i18n/currency.js +0 -85
- package/dist/i18n/date/index.d.ts +0 -203
- package/dist/i18n/date/index.js +0 -531
- package/dist/i18n/date/utils.d.ts +0 -65
- package/dist/i18n/date/utils.js +0 -290
- package/dist/i18n/duration.d.ts +0 -112
- package/dist/i18n/duration.js +0 -392
- package/dist/i18n/format.d.ts +0 -31
- package/dist/i18n/format.js +0 -506
- package/dist/i18n/index.d.ts +0 -8
- package/dist/i18n/index.js +0 -8
- package/dist/itertools/index.d.ts +0 -255
- package/dist/itertools/index.js +0 -437
- package/dist/math/index.d.ts +0 -96
- package/dist/math/index.js +0 -98
- package/dist/mod.d.ts +0 -1
- package/dist/mod.js +0 -1
- package/dist/operators/index.d.ts +0 -152
- package/dist/operators/index.js +0 -305
- package/dist/types.d.ts +0 -19
- package/dist/types.js +0 -1
package/dist/i18n/format.js
DELETED
|
@@ -1,506 +0,0 @@
|
|
|
1
|
-
const NATIVE_DATE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/;
|
|
2
|
-
const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/;
|
|
3
|
-
const REGEX_FORMAT = /\[([^\]]+)]|Y{1,4}|M{1,4}|Q|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|z{1,4}|N{1,4}|LTS?|L{1,4}|l{1,4}|x|X|SSS/g;
|
|
4
|
-
const FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ';
|
|
5
|
-
function padStart(string, length, pad) {
|
|
6
|
-
return String(string).padStart(length, pad);
|
|
7
|
-
}
|
|
8
|
-
function padZoneStr(instance) {
|
|
9
|
-
const negMinutes = -instance.getTimezoneOffset();
|
|
10
|
-
const minutes = Math.abs(negMinutes);
|
|
11
|
-
const hourOffset = Math.floor(minutes / 60);
|
|
12
|
-
const minuteOffset = minutes % 60;
|
|
13
|
-
return `${negMinutes <= 0 ? '+' : '-'}${padStart(hourOffset, 2, '0')}:${padStart(minuteOffset, 2, '0')}`;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Returns a new Date from the given arguments.
|
|
17
|
-
* @param {string | number | Date} date The date value
|
|
18
|
-
* @param {?boolean} [utc=false] Interprets the given value as a UTC date
|
|
19
|
-
* @returns {Date} The new date object
|
|
20
|
-
*/
|
|
21
|
-
export function asDate(date, utc = false) {
|
|
22
|
-
if (date === null) {
|
|
23
|
-
return new Date(NaN);
|
|
24
|
-
}
|
|
25
|
-
if (date === undefined) {
|
|
26
|
-
date = Date.now();
|
|
27
|
-
}
|
|
28
|
-
if (typeof date === 'string' && !/Z$/i.test(date)) {
|
|
29
|
-
const d = date.match(NATIVE_DATE);
|
|
30
|
-
if (d) {
|
|
31
|
-
const m = d[2] - 1 || 0;
|
|
32
|
-
const ms = (d[7] || '0').slice(0, 3);
|
|
33
|
-
if (utc) {
|
|
34
|
-
return new Date(Date.UTC(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms));
|
|
35
|
-
}
|
|
36
|
-
return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const fromDate = new Date(date);
|
|
40
|
-
if (utc) {
|
|
41
|
-
fromDate.setFullYear(fromDate.getUTCFullYear());
|
|
42
|
-
fromDate.setMonth(fromDate.getUTCMonth());
|
|
43
|
-
fromDate.setDate(fromDate.getUTCDate());
|
|
44
|
-
fromDate.setHours(fromDate.getUTCHours());
|
|
45
|
-
fromDate.setMinutes(fromDate.getUTCMinutes());
|
|
46
|
-
fromDate.setSeconds(fromDate.getUTCSeconds());
|
|
47
|
-
fromDate.setMilliseconds(fromDate.getUTCMilliseconds());
|
|
48
|
-
}
|
|
49
|
-
return fromDate;
|
|
50
|
-
}
|
|
51
|
-
const n = 'numeric';
|
|
52
|
-
const s = 'short';
|
|
53
|
-
const l = 'long';
|
|
54
|
-
const dd = '2-digit';
|
|
55
|
-
const STRFTIME = {
|
|
56
|
-
// weekday
|
|
57
|
-
'%A': { weekday: l },
|
|
58
|
-
'%a': { weekday: s },
|
|
59
|
-
'%aa': { weekday: n },
|
|
60
|
-
// day
|
|
61
|
-
'%d': { day: dd },
|
|
62
|
-
'%-d': { day: n },
|
|
63
|
-
// month
|
|
64
|
-
'%m': { month: dd },
|
|
65
|
-
'%-m': { month: n },
|
|
66
|
-
'%B': { month: l },
|
|
67
|
-
'%b': { month: s },
|
|
68
|
-
'%bb': { month: n },
|
|
69
|
-
// year
|
|
70
|
-
'%y': { year: n },
|
|
71
|
-
'%Y': { year: dd },
|
|
72
|
-
// hour
|
|
73
|
-
'%K': { hourCycle: 'h11', hour: dd },
|
|
74
|
-
'%I': { hourCycle: 'h12', hour: dd },
|
|
75
|
-
'%-I': { hourCycle: 'h12', hour: n },
|
|
76
|
-
'%H': { hourCycle: 'h23', hour: dd },
|
|
77
|
-
'%-H': { hourCycle: 'h23', hour: n },
|
|
78
|
-
'%k': { hourCycle: 'h24', hour: n },
|
|
79
|
-
// minutes
|
|
80
|
-
'%M': { minute: dd },
|
|
81
|
-
'%-M': { minute: n },
|
|
82
|
-
// seconds
|
|
83
|
-
'%S': { second: dd },
|
|
84
|
-
'%-S': { second: n },
|
|
85
|
-
// day period
|
|
86
|
-
'%P': { dayPeriod: l },
|
|
87
|
-
'%p': { dayPeriod: s },
|
|
88
|
-
'%pp': { dayPeriod: 'narrow' },
|
|
89
|
-
// era
|
|
90
|
-
'%N': { era: l, year: dd },
|
|
91
|
-
'%n': { era: s, year: dd },
|
|
92
|
-
'%nn': { era: n, year: 'narrow' },
|
|
93
|
-
// timeZoneName
|
|
94
|
-
// '%Z': { timeZoneName: 'longGeneric', year: dd },
|
|
95
|
-
// '%-Z': { timeZoneName: 'shortGeneric', year: dd },
|
|
96
|
-
'%z': { timeZoneName: 'longOffset', year: dd },
|
|
97
|
-
'%-z': { timeZoneName: 'shortOffset', year: dd },
|
|
98
|
-
'%Z': { timeZoneName: l, year: dd },
|
|
99
|
-
'%-Z': { timeZoneName: s, year: dd }
|
|
100
|
-
};
|
|
101
|
-
const TOKENS = {
|
|
102
|
-
// weekday
|
|
103
|
-
dddd: { weekday: l },
|
|
104
|
-
ddd: { weekday: s },
|
|
105
|
-
E: { weekday: n },
|
|
106
|
-
// day
|
|
107
|
-
DD: { day: dd },
|
|
108
|
-
D: { day: n },
|
|
109
|
-
// month
|
|
110
|
-
MM: { month: dd },
|
|
111
|
-
M: { month: n },
|
|
112
|
-
MMMM: { month: l },
|
|
113
|
-
MMM: { month: s },
|
|
114
|
-
// year
|
|
115
|
-
YYYY: { year: n },
|
|
116
|
-
YY: { year: dd },
|
|
117
|
-
// hour
|
|
118
|
-
hh: { hourCycle: 'h12', hour: dd },
|
|
119
|
-
h: { hourCycle: 'h12', hour: n },
|
|
120
|
-
HH: { hourCycle: 'h23', hour: dd },
|
|
121
|
-
H: { hourCycle: 'h23', hour: n },
|
|
122
|
-
kk: { hourCycle: 'h11', hour: dd },
|
|
123
|
-
k: { hourCycle: 'h24', hour: n },
|
|
124
|
-
// minutes
|
|
125
|
-
mm: { minute: dd },
|
|
126
|
-
m: { minute: n },
|
|
127
|
-
// seconds
|
|
128
|
-
ss: { second: dd },
|
|
129
|
-
s: { second: n },
|
|
130
|
-
// day period
|
|
131
|
-
A: { dayPeriod: l },
|
|
132
|
-
a: { dayPeriod: s },
|
|
133
|
-
// era
|
|
134
|
-
N: { era: s, year: dd },
|
|
135
|
-
NN: { era: s, year: dd },
|
|
136
|
-
NNN: { era: s, year: dd },
|
|
137
|
-
NNNN: { era: l, year: dd },
|
|
138
|
-
// timeZoneName
|
|
139
|
-
ZZ: { timeZoneName: 'longOffset', year: dd },
|
|
140
|
-
Z: { timeZoneName: 'shortOffset', year: dd },
|
|
141
|
-
zzz: { timeZoneName: l, year: dd },
|
|
142
|
-
z: { timeZoneName: s, year: dd }
|
|
143
|
-
};
|
|
144
|
-
const HOUR_PARTS = { '%I': 1, '%-I': 1, '%K': 1, '%k': 1 };
|
|
145
|
-
const ERA_PARTS = { '%n': 1, '%N': 1, '%nn': 1 };
|
|
146
|
-
const TZ_PARTS = { '%ZZ': 1, '%-ZZ': 1, '%-z': 1, '%z': 1, '%-Z': 1, '%Z': 1 };
|
|
147
|
-
function formatter(locale, opts) {
|
|
148
|
-
return new Intl.DateTimeFormat(locale, opts);
|
|
149
|
-
}
|
|
150
|
-
function formatHour(h, maxLength) {
|
|
151
|
-
return String(h % 12 || 12).padStart(maxLength, '0');
|
|
152
|
-
}
|
|
153
|
-
function formatMeridiem(hour, isLowercase) {
|
|
154
|
-
const m = hour < 12 ? 'AM' : 'PM';
|
|
155
|
-
return isLowercase ? m.toLowerCase() : m;
|
|
156
|
-
}
|
|
157
|
-
function formatPart(locale, t, date) {
|
|
158
|
-
const value = formatter(locale, TOKENS[t]).format(date);
|
|
159
|
-
return value.split(/\s+/g).slice(1).join(' ');
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Returns a localized string representation of this date, according to the given format string. Format codes use the same specification as {@link https://momentjs.com/docs/#/displaying/format/ moment}.
|
|
163
|
-
* @param {string} str The format string to use
|
|
164
|
-
* @see {@link https://momentjs.com/docs/#/displaying/format/ List of formats}
|
|
165
|
-
* @example
|
|
166
|
-
```js
|
|
167
|
-
formatDate(new Date(), 'MM/DD/YYYY') // '10/31/2022'
|
|
168
|
-
```
|
|
169
|
-
*/
|
|
170
|
-
export function formatDate(formatStr, date, locale) {
|
|
171
|
-
const str = formatStr || FORMAT_DEFAULT;
|
|
172
|
-
const zoneStr = padZoneStr(date);
|
|
173
|
-
const time = {
|
|
174
|
-
H: date.getHours(),
|
|
175
|
-
HH: padStart(date.getHours(), 2, '0'),
|
|
176
|
-
h: formatHour(date.getHours(), 1),
|
|
177
|
-
hh: formatHour(date.getHours(), 2),
|
|
178
|
-
a: formatMeridiem(date.getHours(), true),
|
|
179
|
-
A: formatMeridiem(date.getHours()),
|
|
180
|
-
m: date.getMinutes(),
|
|
181
|
-
mm: padStart(date.getMinutes(), 2, '0'),
|
|
182
|
-
s: date.getSeconds(),
|
|
183
|
-
ss: padStart(date.getSeconds(), 2, '0'),
|
|
184
|
-
SSS: padStart(date.getMilliseconds(), 3, '0'),
|
|
185
|
-
X: Math.floor(date.getTime() / 1000),
|
|
186
|
-
x: date.getTime()
|
|
187
|
-
};
|
|
188
|
-
const matches = {
|
|
189
|
-
...time,
|
|
190
|
-
N: formatPart(locale, 'N', date),
|
|
191
|
-
NN: formatPart(locale, 'NN', date),
|
|
192
|
-
NNN: formatPart(locale, 'NNN', date),
|
|
193
|
-
NNNN: formatPart(locale, 'NNNN', date),
|
|
194
|
-
YY: String(date.getFullYear()).slice(-2),
|
|
195
|
-
YYYY: date.getFullYear(),
|
|
196
|
-
M: date.getMonth() + 1,
|
|
197
|
-
MM: padStart(date.getMonth() + 1, 2, '0'),
|
|
198
|
-
MMM: formatter(locale, TOKENS.MMM).format(date),
|
|
199
|
-
MMMM: formatter(locale, TOKENS.MMMM).format(date),
|
|
200
|
-
Q: Math.ceil((date.getMonth() + 1) / 3),
|
|
201
|
-
D: date.getDate(),
|
|
202
|
-
DD: padStart(date.getDate(), 2, '0'),
|
|
203
|
-
d: date.getDay(),
|
|
204
|
-
ddd: formatter(locale, TOKENS.ddd).format(date),
|
|
205
|
-
dddd: formatter(locale, TOKENS.dddd).format(date),
|
|
206
|
-
Z: formatPart(locale, 'Z', date),
|
|
207
|
-
ZZ: formatPart(locale, 'ZZ', date),
|
|
208
|
-
z: formatPart(locale, 'z', date),
|
|
209
|
-
zzz: formatPart(locale, 'zzz', date),
|
|
210
|
-
LT: `${time.h}:${time.mm} ${time.A}`,
|
|
211
|
-
LTS: `${time.h}:${time.mm}:${time.ss} ${time.A}`,
|
|
212
|
-
L: formatter(locale, DATE_SHORT_DD).format(date),
|
|
213
|
-
LL: formatter(locale, DATE_FULL).format(date),
|
|
214
|
-
LLL: formatter(locale, DATE_LONG_TIME).format(date),
|
|
215
|
-
LLLL: formatter(locale, DATE_HUGE).format(date),
|
|
216
|
-
l: formatter(locale, DATE_SHORT).format(date),
|
|
217
|
-
ll: formatter(locale, DATE_MED).format(date),
|
|
218
|
-
lll: formatter(locale, DATE_MED_TIME).format(date),
|
|
219
|
-
llll: formatter(locale, DATE_MED_WITH_WEEKDAY).format(date)
|
|
220
|
-
};
|
|
221
|
-
return str.replace(REGEX_FORMAT, (match, $1) => $1 || matches[match] || zoneStr.replace(':', '')); // 'ZZ'
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Formats a date using a formatting string in the {@link https://strftime.org/ strftime} format, in any given locale.
|
|
225
|
-
* @param {string} fmt The format string to apply
|
|
226
|
-
* @param {Date} date The date value
|
|
227
|
-
* @param {?string} locale The locale to use when formatting (default is system locale).
|
|
228
|
-
* @returns {string} The string representation of date
|
|
229
|
-
* @see {@link https://strftime.org/ strftime format}
|
|
230
|
-
* @example
|
|
231
|
-
```js
|
|
232
|
-
strftime('%A, %d/%m/%y', new Date())
|
|
233
|
-
// 'Saturday, 01/02/2020'
|
|
234
|
-
```
|
|
235
|
-
*/
|
|
236
|
-
export function strftime(fmt, date, locale) {
|
|
237
|
-
const results = [];
|
|
238
|
-
let dayPeriod = '';
|
|
239
|
-
let dayPeriodIndex = -1;
|
|
240
|
-
for (let i = 0; i < fmt.length; i++) {
|
|
241
|
-
let part = fmt[i];
|
|
242
|
-
if (part === '%') {
|
|
243
|
-
// check for escaped '%'
|
|
244
|
-
if (fmt[++i] === '%') {
|
|
245
|
-
results.push('%');
|
|
246
|
-
continue;
|
|
247
|
-
}
|
|
248
|
-
if (fmt[i] === '-') {
|
|
249
|
-
part += fmt[i++];
|
|
250
|
-
}
|
|
251
|
-
part += fmt[i];
|
|
252
|
-
// add any repeated characters that come after
|
|
253
|
-
while (i < fmt.length - 1 && fmt[i + 1] === fmt[i])
|
|
254
|
-
part += fmt[++i];
|
|
255
|
-
if (HOUR_PARTS[part]) {
|
|
256
|
-
const res = formatter(locale, STRFTIME[part]).format(date).split(/\s+/g);
|
|
257
|
-
// save the AM/PM for the correct spot
|
|
258
|
-
results.push(res[0]);
|
|
259
|
-
dayPeriod = res[1];
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
if (part === '%P' || part === '%p') {
|
|
263
|
-
// leave this flag in place for later
|
|
264
|
-
dayPeriodIndex = results.length;
|
|
265
|
-
if (part === '%p' && dayPeriod) {
|
|
266
|
-
dayPeriod = dayPeriod.toLowerCase();
|
|
267
|
-
}
|
|
268
|
-
results.push(part);
|
|
269
|
-
continue;
|
|
270
|
-
}
|
|
271
|
-
if (ERA_PARTS[part] || TZ_PARTS[part]) {
|
|
272
|
-
// the formatting includes the date/year so we take what comes after
|
|
273
|
-
const res = formatter(locale, STRFTIME[part]).format(date).split(/\s+/g);
|
|
274
|
-
results.push(res.slice(1).join(' '));
|
|
275
|
-
continue;
|
|
276
|
-
}
|
|
277
|
-
// format any other parts
|
|
278
|
-
let res = formatter(locale, STRFTIME[part]).format(date);
|
|
279
|
-
// fix bugs in time formatter
|
|
280
|
-
if ((part === '%S' || part === '%M') && res.length === 1)
|
|
281
|
-
res = '0' + res;
|
|
282
|
-
results.push(res);
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
// output as literal
|
|
286
|
-
results.push(part);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
// insert the AM/PM at the correct spot
|
|
290
|
-
if (dayPeriodIndex >= 0)
|
|
291
|
-
results[dayPeriodIndex] = dayPeriod || '';
|
|
292
|
-
return results.join('').trim();
|
|
293
|
-
}
|
|
294
|
-
const DATETIME_DEFAULT = {};
|
|
295
|
-
/** L: 09/04/1983 */
|
|
296
|
-
const DATE_SHORT_DD = {
|
|
297
|
-
year: n,
|
|
298
|
-
month: dd,
|
|
299
|
-
day: dd
|
|
300
|
-
};
|
|
301
|
-
/** l: 9/4/1983 */
|
|
302
|
-
const DATE_SHORT = {
|
|
303
|
-
year: n,
|
|
304
|
-
month: n,
|
|
305
|
-
day: n
|
|
306
|
-
};
|
|
307
|
-
/** ll: Oct 14, 1983 */
|
|
308
|
-
const DATE_MED = {
|
|
309
|
-
year: n,
|
|
310
|
-
month: s,
|
|
311
|
-
day: n
|
|
312
|
-
};
|
|
313
|
-
/** LL: October 14, 1983 */
|
|
314
|
-
const DATE_FULL = {
|
|
315
|
-
year: n,
|
|
316
|
-
month: l,
|
|
317
|
-
day: n
|
|
318
|
-
};
|
|
319
|
-
/** lll: Oct 14, 1983 8:30 PM */
|
|
320
|
-
const DATE_MED_TIME = {
|
|
321
|
-
year: n,
|
|
322
|
-
month: s,
|
|
323
|
-
day: n,
|
|
324
|
-
hour: n,
|
|
325
|
-
minute: n,
|
|
326
|
-
hourCycle: 'h12'
|
|
327
|
-
};
|
|
328
|
-
/** LLL: October 14, 1983 8:30 PM */
|
|
329
|
-
const DATE_LONG_TIME = {
|
|
330
|
-
year: n,
|
|
331
|
-
month: l,
|
|
332
|
-
day: n,
|
|
333
|
-
hour: n,
|
|
334
|
-
minute: n,
|
|
335
|
-
hourCycle: 'h12'
|
|
336
|
-
};
|
|
337
|
-
/** llll: Fri, Oct 14, 1983, 8:30 PM */
|
|
338
|
-
const DATE_MED_WITH_WEEKDAY = {
|
|
339
|
-
year: n,
|
|
340
|
-
month: s,
|
|
341
|
-
day: n,
|
|
342
|
-
weekday: s,
|
|
343
|
-
hour: n,
|
|
344
|
-
minute: n,
|
|
345
|
-
hourCycle: 'h12'
|
|
346
|
-
};
|
|
347
|
-
/** LLLL: Tuesday, October 14, 1983, 8:30 PM */
|
|
348
|
-
const DATE_HUGE = {
|
|
349
|
-
year: n,
|
|
350
|
-
month: l,
|
|
351
|
-
day: n,
|
|
352
|
-
weekday: l,
|
|
353
|
-
hour: n,
|
|
354
|
-
minute: n,
|
|
355
|
-
hourCycle: 'h12'
|
|
356
|
-
};
|
|
357
|
-
/** LT: 09:30 AM */
|
|
358
|
-
const TIME_SIMPLE = {
|
|
359
|
-
hour: n,
|
|
360
|
-
minute: n,
|
|
361
|
-
hourCycle: 'h12'
|
|
362
|
-
};
|
|
363
|
-
/** LTS: 09:30:23 AM */
|
|
364
|
-
const TIME_WITH_SECONDS = {
|
|
365
|
-
hour: n,
|
|
366
|
-
minute: n,
|
|
367
|
-
second: n,
|
|
368
|
-
hourCycle: 'h12'
|
|
369
|
-
};
|
|
370
|
-
/** 09:30:23 AM EDT */
|
|
371
|
-
const TIME_WITH_SHORT_OFFSET = {
|
|
372
|
-
hour: n,
|
|
373
|
-
minute: n,
|
|
374
|
-
second: n,
|
|
375
|
-
timeZoneName: s,
|
|
376
|
-
hourCycle: 'h12'
|
|
377
|
-
};
|
|
378
|
-
/** 09:30:23 AM Eastern Daylight Time */
|
|
379
|
-
const TIME_WITH_LONG_OFFSET = {
|
|
380
|
-
hour: n,
|
|
381
|
-
minute: n,
|
|
382
|
-
second: n,
|
|
383
|
-
timeZoneName: l,
|
|
384
|
-
hourCycle: 'h12'
|
|
385
|
-
};
|
|
386
|
-
/** 09:30 */
|
|
387
|
-
const TIME_24_SIMPLE = {
|
|
388
|
-
hour: n,
|
|
389
|
-
minute: n,
|
|
390
|
-
hourCycle: 'h23'
|
|
391
|
-
};
|
|
392
|
-
/** 09:30:23 */
|
|
393
|
-
const TIME_24_WITH_SECONDS = {
|
|
394
|
-
hour: n,
|
|
395
|
-
minute: n,
|
|
396
|
-
second: n,
|
|
397
|
-
hourCycle: 'h23'
|
|
398
|
-
};
|
|
399
|
-
/** 09:30:23 EDT */
|
|
400
|
-
const TIME_24_WITH_SHORT_OFFSET = {
|
|
401
|
-
hour: n,
|
|
402
|
-
minute: n,
|
|
403
|
-
second: n,
|
|
404
|
-
hourCycle: 'h23',
|
|
405
|
-
timeZoneName: s
|
|
406
|
-
};
|
|
407
|
-
/** 09:30:23 Eastern Daylight Time */
|
|
408
|
-
const TIME_24_WITH_LONG_OFFSET = {
|
|
409
|
-
hour: n,
|
|
410
|
-
minute: n,
|
|
411
|
-
second: n,
|
|
412
|
-
hourCycle: 'h23',
|
|
413
|
-
timeZoneName: l
|
|
414
|
-
};
|
|
415
|
-
/** 10/14/1983, 9:30 AM */
|
|
416
|
-
const DATETIME_SHORT = {
|
|
417
|
-
year: n,
|
|
418
|
-
month: n,
|
|
419
|
-
day: n,
|
|
420
|
-
hour: n,
|
|
421
|
-
minute: n,
|
|
422
|
-
hourCycle: 'h12'
|
|
423
|
-
};
|
|
424
|
-
/** 10/14/1983, 9:30:33 AM */
|
|
425
|
-
const DATETIME_SHORT_WITH_SECONDS = {
|
|
426
|
-
year: n,
|
|
427
|
-
month: n,
|
|
428
|
-
day: n,
|
|
429
|
-
hour: n,
|
|
430
|
-
minute: n,
|
|
431
|
-
second: n,
|
|
432
|
-
hourCycle: 'h12'
|
|
433
|
-
};
|
|
434
|
-
/** Oct 14, 1983, 9:30 AM */
|
|
435
|
-
const DATETIME_MED = {
|
|
436
|
-
year: n,
|
|
437
|
-
month: s,
|
|
438
|
-
day: n,
|
|
439
|
-
hour: n,
|
|
440
|
-
minute: n,
|
|
441
|
-
hourCycle: 'h12'
|
|
442
|
-
};
|
|
443
|
-
/** Oct 14, 1983, 9:30:33 AM */
|
|
444
|
-
const DATETIME_MED_WITH_SECONDS = {
|
|
445
|
-
year: n,
|
|
446
|
-
month: s,
|
|
447
|
-
day: n,
|
|
448
|
-
hour: n,
|
|
449
|
-
minute: n,
|
|
450
|
-
second: n,
|
|
451
|
-
hourCycle: 'h12'
|
|
452
|
-
};
|
|
453
|
-
/** Fri, 14 Oct 1983, 9:30 AM */
|
|
454
|
-
const DATETIME_MED_WITH_WEEKDAY = {
|
|
455
|
-
year: n,
|
|
456
|
-
month: s,
|
|
457
|
-
day: n,
|
|
458
|
-
weekday: s,
|
|
459
|
-
hour: n,
|
|
460
|
-
minute: n,
|
|
461
|
-
hourCycle: 'h12'
|
|
462
|
-
};
|
|
463
|
-
/** October 14, 1983, 9:30 AM EDT */
|
|
464
|
-
const DATETIME_FULL = {
|
|
465
|
-
year: n,
|
|
466
|
-
month: l,
|
|
467
|
-
day: n,
|
|
468
|
-
hour: n,
|
|
469
|
-
minute: n,
|
|
470
|
-
timeZoneName: s,
|
|
471
|
-
hourCycle: 'h12'
|
|
472
|
-
};
|
|
473
|
-
/** October 14, 1983, 9:30:33 AM EDT */
|
|
474
|
-
const DATETIME_FULL_WITH_SECONDS = {
|
|
475
|
-
year: n,
|
|
476
|
-
month: l,
|
|
477
|
-
day: n,
|
|
478
|
-
hour: n,
|
|
479
|
-
minute: n,
|
|
480
|
-
second: n,
|
|
481
|
-
timeZoneName: s,
|
|
482
|
-
hourCycle: 'h12'
|
|
483
|
-
};
|
|
484
|
-
/** Friday, October 14, 1983, 9:30 AM Eastern Daylight Time */
|
|
485
|
-
const DATETIME_HUGE = {
|
|
486
|
-
year: n,
|
|
487
|
-
month: l,
|
|
488
|
-
day: n,
|
|
489
|
-
weekday: l,
|
|
490
|
-
hour: n,
|
|
491
|
-
minute: n,
|
|
492
|
-
timeZoneName: l,
|
|
493
|
-
hourCycle: 'h12'
|
|
494
|
-
};
|
|
495
|
-
/** Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time */
|
|
496
|
-
const DATETIME_HUGE_WITH_SECONDS = {
|
|
497
|
-
year: n,
|
|
498
|
-
month: l,
|
|
499
|
-
day: n,
|
|
500
|
-
weekday: l,
|
|
501
|
-
hour: n,
|
|
502
|
-
minute: n,
|
|
503
|
-
second: n,
|
|
504
|
-
timeZoneName: l,
|
|
505
|
-
hourCycle: 'h12'
|
|
506
|
-
};
|
package/dist/i18n/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module includes functions and classes to handle internationalization of dates and currencies.
|
|
3
|
-
*
|
|
4
|
-
* @module i18n
|
|
5
|
-
*/
|
|
6
|
-
export * from './currency.js';
|
|
7
|
-
export * from './date/index.js';
|
|
8
|
-
export { Duration, TDuration, DurationUnit } from './duration.js';
|
package/dist/i18n/index.js
DELETED