atomic-fns 1.2.0 → 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.
Files changed (216) hide show
  1. package/README.md +397 -91
  2. package/dist/array/index.d.ts +9 -0
  3. package/dist/array/index.js +9 -0
  4. package/dist/array/list.d.ts +99 -0
  5. package/dist/array/list.js +133 -0
  6. package/dist/array/sets.d.ts +130 -0
  7. package/dist/array/sets.js +213 -0
  8. package/dist/async/index.d.ts +6 -0
  9. package/dist/async/index.js +6 -0
  10. package/dist/async/retry.d.ts +38 -0
  11. package/dist/async/retry.js +56 -0
  12. package/dist/async/sleep.d.ts +42 -0
  13. package/dist/async/sleep.js +76 -0
  14. package/dist/collections/bisect.d.ts +103 -0
  15. package/dist/collections/bisect.js +157 -0
  16. package/dist/collections/deque.d.ts +67 -97
  17. package/dist/collections/deque.js +197 -256
  18. package/dist/collections/entries.d.ts +89 -0
  19. package/dist/collections/entries.js +131 -0
  20. package/dist/collections/frozen-set.d.ts +42 -0
  21. package/dist/collections/frozen-set.js +64 -0
  22. package/dist/collections/group.d.ts +141 -0
  23. package/dist/collections/group.js +241 -0
  24. package/dist/collections/heap.d.ts +64 -0
  25. package/dist/collections/heap.js +205 -0
  26. package/dist/collections/index.d.ts +15 -623
  27. package/dist/collections/index.js +14 -844
  28. package/dist/collections/internal/arrayKeys.d.ts +19 -0
  29. package/dist/collections/internal/arrayKeys.js +83 -0
  30. package/dist/collections/internal/invariants.d.ts +4 -0
  31. package/dist/collections/internal/invariants.js +12 -0
  32. package/dist/collections/internal/iterable.d.ts +25 -0
  33. package/dist/collections/internal/iterable.js +62 -0
  34. package/dist/collections/iterate.d.ts +162 -0
  35. package/dist/collections/iterate.js +188 -0
  36. package/dist/collections/lru-cache.d.ts +58 -0
  37. package/dist/collections/lru-cache.js +164 -0
  38. package/dist/collections/order.d.ts +19 -0
  39. package/dist/collections/order.js +38 -0
  40. package/dist/collections/shape.d.ts +32 -0
  41. package/dist/collections/shape.js +86 -0
  42. package/dist/collections/sorted-map.d.ts +171 -0
  43. package/dist/collections/sorted-map.js +845 -0
  44. package/dist/collections/sorted-set.d.ts +103 -0
  45. package/dist/collections/sorted-set.js +147 -0
  46. package/dist/collections/splay-tree.d.ts +82 -0
  47. package/dist/collections/splay-tree.js +354 -0
  48. package/dist/collections/trie.d.ts +58 -0
  49. package/dist/collections/trie.js +196 -0
  50. package/dist/decimal/currency.d.ts +211 -0
  51. package/dist/decimal/currency.js +321 -0
  52. package/dist/decimal/decimal.d.ts +299 -0
  53. package/dist/decimal/decimal.js +660 -0
  54. package/dist/decimal/index.d.ts +11 -148
  55. package/dist/decimal/index.js +10 -410
  56. package/dist/decimal/internal/bits.d.ts +2 -0
  57. package/dist/decimal/internal/bits.js +7 -0
  58. package/dist/decimal/internal/echo.d.ts +4 -0
  59. package/dist/decimal/internal/echo.js +6 -0
  60. package/dist/decimal/internal/isqrt.d.ts +9 -0
  61. package/dist/decimal/internal/isqrt.js +34 -0
  62. package/dist/decimal/internal/locale.d.ts +7 -0
  63. package/dist/decimal/internal/locale.js +24 -0
  64. package/dist/decimal/internal/minor-units.d.ts +2 -0
  65. package/dist/decimal/internal/minor-units.js +33 -0
  66. package/dist/decimal/internal/pow10.d.ts +24 -0
  67. package/dist/decimal/internal/pow10.js +96 -0
  68. package/dist/encoding/base64.d.ts +39 -0
  69. package/dist/encoding/base64.js +53 -0
  70. package/dist/encoding/hex.d.ts +23 -0
  71. package/dist/encoding/hex.js +34 -0
  72. package/dist/encoding/index.d.ts +6 -0
  73. package/dist/encoding/index.js +6 -0
  74. package/dist/function/debounce.d.ts +68 -0
  75. package/dist/function/debounce.js +203 -0
  76. package/dist/function/index.d.ts +6 -0
  77. package/dist/function/index.js +6 -0
  78. package/dist/function/shared.d.ts +2 -0
  79. package/dist/function/shared.js +5 -0
  80. package/dist/function/wrap.d.ts +130 -0
  81. package/dist/function/wrap.js +113 -0
  82. package/dist/hash/digest.d.ts +18 -0
  83. package/dist/hash/digest.js +26 -0
  84. package/dist/hash/hash.d.ts +22 -0
  85. package/dist/hash/hash.js +252 -0
  86. package/dist/hash/hashString.d.ts +13 -0
  87. package/dist/hash/hashString.js +53 -0
  88. package/dist/hash/index.d.ts +8 -0
  89. package/dist/hash/index.js +8 -0
  90. package/dist/hash/stableStringify.d.ts +19 -0
  91. package/dist/hash/stableStringify.js +102 -0
  92. package/dist/id/index.d.ts +7 -0
  93. package/dist/id/index.js +7 -0
  94. package/dist/id/nanoid.d.ts +16 -0
  95. package/dist/id/nanoid.js +65 -0
  96. package/dist/id/uniqueId.d.ts +14 -0
  97. package/dist/id/uniqueId.js +20 -0
  98. package/dist/id/uuid.d.ts +25 -0
  99. package/dist/id/uuid.js +64 -0
  100. package/dist/index.d.ts +15 -8
  101. package/dist/index.js +15 -8
  102. package/dist/internal/bytes.d.ts +11 -0
  103. package/dist/internal/bytes.js +33 -0
  104. package/dist/internal/codec.d.ts +11 -0
  105. package/dist/internal/codec.js +84 -0
  106. package/dist/internal/compare.d.ts +10 -0
  107. package/dist/internal/compare.js +26 -0
  108. package/dist/internal/crypto.d.ts +5 -0
  109. package/dist/internal/crypto.js +11 -0
  110. package/dist/internal/keys.d.ts +12 -0
  111. package/dist/internal/keys.js +23 -0
  112. package/dist/internal/kind.d.ts +44 -0
  113. package/dist/internal/kind.js +139 -0
  114. package/dist/internal/sparse.d.ts +51 -0
  115. package/dist/internal/sparse.js +104 -0
  116. package/dist/internal/text.d.ts +7 -0
  117. package/dist/internal/text.js +15 -0
  118. package/dist/internal/timer.d.ts +10 -0
  119. package/dist/internal/timer.js +17 -0
  120. package/dist/internal/truncate.d.ts +10 -0
  121. package/dist/internal/truncate.js +22 -0
  122. package/dist/internal/walk.d.ts +47 -0
  123. package/dist/internal/walk.js +100 -0
  124. package/dist/is/index.d.ts +8 -0
  125. package/dist/is/index.js +8 -0
  126. package/dist/is/isArrayLike.d.ts +18 -0
  127. package/dist/is/isArrayLike.js +25 -0
  128. package/dist/is/isError.d.ts +13 -0
  129. package/dist/is/isError.js +18 -0
  130. package/dist/is/isNil.d.ts +12 -0
  131. package/dist/is/isNil.js +14 -0
  132. package/dist/is/isPlainObject.d.ts +15 -0
  133. package/dist/is/isPlainObject.js +34 -0
  134. package/dist/number/index.d.ts +7 -0
  135. package/dist/number/index.js +7 -0
  136. package/dist/number/round.d.ts +86 -0
  137. package/dist/number/round.js +130 -0
  138. package/dist/number/stats.d.ts +52 -0
  139. package/dist/number/stats.js +115 -0
  140. package/dist/object/cloneDeep.d.ts +28 -0
  141. package/dist/object/cloneDeep.js +200 -0
  142. package/dist/object/index.d.ts +14 -0
  143. package/dist/object/index.js +13 -0
  144. package/dist/object/isEqual.d.ts +64 -0
  145. package/dist/object/isEqual.js +289 -0
  146. package/dist/object/matches.d.ts +40 -0
  147. package/dist/object/matches.js +284 -0
  148. package/dist/object/merge.d.ts +66 -0
  149. package/dist/object/merge.js +272 -0
  150. package/dist/object/parsePath.d.ts +22 -0
  151. package/dist/object/parsePath.js +111 -0
  152. package/dist/object/path.d.ts +85 -0
  153. package/dist/object/path.js +208 -0
  154. package/dist/object/pick.d.ts +91 -0
  155. package/dist/object/pick.js +180 -0
  156. package/dist/object/reshape.d.ts +73 -0
  157. package/dist/object/reshape.js +144 -0
  158. package/dist/random/index.d.ts +96 -32
  159. package/dist/random/index.js +215 -53
  160. package/dist/string/case.d.ts +71 -0
  161. package/dist/string/case.js +152 -0
  162. package/dist/string/fold.d.ts +35 -0
  163. package/dist/string/fold.js +100 -0
  164. package/dist/string/index.d.ts +6 -187
  165. package/dist/string/index.js +6 -224
  166. package/dist/string/truncate.d.ts +25 -0
  167. package/dist/string/truncate.js +44 -0
  168. package/dist/string/words.d.ts +27 -0
  169. package/dist/string/words.js +241 -0
  170. package/package.json +99 -51
  171. package/dist/collections/BTree.d.ts +0 -230
  172. package/dist/collections/BTree.js +0 -1143
  173. package/dist/collections/Heap.d.ts +0 -69
  174. package/dist/collections/Heap.js +0 -181
  175. package/dist/collections/LRUCache.d.ts +0 -83
  176. package/dist/collections/LRUCache.js +0 -139
  177. package/dist/collections/SortedMap.d.ts +0 -92
  178. package/dist/collections/SortedMap.js +0 -131
  179. package/dist/collections/SortedSet.d.ts +0 -69
  180. package/dist/collections/SortedSet.js +0 -99
  181. package/dist/collections/SortedTree.d.ts +0 -103
  182. package/dist/collections/SortedTree.js +0 -142
  183. package/dist/collections/SplayTree.d.ts +0 -107
  184. package/dist/collections/SplayTree.js +0 -351
  185. package/dist/collections/Trie.d.ts +0 -42
  186. package/dist/collections/Trie.js +0 -104
  187. package/dist/collections/abc.d.ts +0 -152
  188. package/dist/collections/abc.js +0 -39
  189. package/dist/collections/frozenset.d.ts +0 -19
  190. package/dist/collections/frozenset.js +0 -33
  191. package/dist/functools/index.d.ts +0 -106
  192. package/dist/functools/index.js +0 -203
  193. package/dist/globals/index.d.ts +0 -268
  194. package/dist/globals/index.js +0 -447
  195. package/dist/i18n/currency.d.ts +0 -27
  196. package/dist/i18n/currency.js +0 -100
  197. package/dist/i18n/date/index.d.ts +0 -210
  198. package/dist/i18n/date/index.js +0 -552
  199. package/dist/i18n/date/utils.d.ts +0 -64
  200. package/dist/i18n/date/utils.js +0 -192
  201. package/dist/i18n/duration.d.ts +0 -113
  202. package/dist/i18n/duration.js +0 -398
  203. package/dist/i18n/format.d.ts +0 -34
  204. package/dist/i18n/format.js +0 -378
  205. package/dist/i18n/index.d.ts +0 -9
  206. package/dist/i18n/index.js +0 -8
  207. package/dist/itertools/index.d.ts +0 -251
  208. package/dist/itertools/index.js +0 -434
  209. package/dist/math/index.d.ts +0 -79
  210. package/dist/math/index.js +0 -81
  211. package/dist/mod.d.ts +0 -1
  212. package/dist/mod.js +0 -1
  213. package/dist/operators/index.d.ts +0 -148
  214. package/dist/operators/index.js +0 -325
  215. package/dist/types.d.ts +0 -19
  216. package/dist/types.js +0 -1
@@ -1,34 +0,0 @@
1
- export declare function fromFields(utc: boolean, year: number, month: any, day: any, hour: any, minute: any, second: any, ms: any): Date;
2
- /**
3
- * Returns a new Date from the given arguments.
4
- * @param {string | number | Date} date The date value
5
- * @param {?boolean} [utc=false] Interprets the given value as a UTC date
6
- * @returns {Date} The new date object
7
- */
8
- export declare function asDate(date: string | number | Date, utc?: boolean): Date;
9
- /**
10
- * 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}.
11
- * @param {string} formatStr The format string to use
12
- * @param {Date} date The date value
13
- * @param {?string} locale The locale to use when formatting (default is system locale).
14
- * @see {@link https://momentjs.com/docs/#/displaying/format/ List of formats}
15
- * @example
16
- ```js
17
- formatDate('MM/DD/YYYY', new Date()) // '10/31/2022'
18
- ```
19
- */
20
- export declare function formatDate(formatStr: string, date: Date, locale?: string): string;
21
- /**
22
- * Formats a date using a formatting string in the {@link https://strftime.org/ strftime} format, in any given locale.
23
- * @param {string} fmt The format string to apply
24
- * @param {Date} date The date value
25
- * @param {?string} locale The locale to use when formatting (default is system locale).
26
- * @returns {string} The string representation of date
27
- * @see {@link https://strftime.org/ strftime format}
28
- * @example
29
- ```js
30
- strftime('%A, %d/%m/%y', new Date())
31
- // 'Saturday, 01/02/2020'
32
- ```
33
- */
34
- export declare function strftime(fmt: string, date: Date, locale?: string): string;
@@ -1,378 +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_FORMAT = /\[([^\]]+)]|Y{1,4}|M{1,4}|Q|Do|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;
3
- const FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ';
4
- const INVALID_DATE_STRING = 'Invalid Date';
5
- const ORDINAL_SUFFIXES = { one: 'st', two: 'nd', few: 'rd', other: 'th' };
6
- function padStart(string, length, pad) {
7
- return String(string).padStart(length, pad);
8
- }
9
- function padYear(year) {
10
- return `${year < 0 ? '-' : ''}${padStart(Math.abs(year), 4, '0')}`;
11
- }
12
- function padZoneStr(instance) {
13
- const negMinutes = -instance.getTimezoneOffset();
14
- const minutes = Math.abs(negMinutes);
15
- const hourOffset = Math.floor(minutes / 60);
16
- const minuteOffset = minutes % 60;
17
- return `${negMinutes >= 0 ? '+' : '-'}${padStart(hourOffset, 2, '0')}:${padStart(minuteOffset, 2, '0')}`;
18
- }
19
- export function fromFields(utc, year, month, day, hour, minute, second, ms) {
20
- // Date reads the years 0 to 99 as 1900 to 1999, 400 years later the leap years still match
21
- const shift = year >= 0 && year < 100 ? 400 : 0;
22
- if (utc) {
23
- const date = new Date(Date.UTC(year + shift, month, day, hour, minute, second, ms));
24
- date.setUTCFullYear(date.getUTCFullYear() - shift);
25
- return date;
26
- }
27
- const date = new Date(year + shift, month, day, hour, minute, second, ms);
28
- date.setFullYear(date.getFullYear() - shift);
29
- return date;
30
- }
31
- /**
32
- * Returns a new Date from the given arguments.
33
- * @param {string | number | Date} date The date value
34
- * @param {?boolean} [utc=false] Interprets the given value as a UTC date
35
- * @returns {Date} The new date object
36
- */
37
- export function asDate(date, utc = false) {
38
- if (date === null) {
39
- return new Date(NaN);
40
- }
41
- if (date === undefined) {
42
- date = Date.now();
43
- }
44
- if (typeof date === 'string' && !/Z$/i.test(date)) {
45
- const d = date.match(NATIVE_DATE);
46
- if (d) {
47
- const m = d[2] - 1 || 0;
48
- const ms = (d[7] || '').padEnd(3, '0').slice(0, 3);
49
- return fromFields(utc, Number(d[1]), m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms);
50
- }
51
- }
52
- const fromDate = new Date(date);
53
- if (utc) {
54
- return fromFields(false, fromDate.getUTCFullYear(), fromDate.getUTCMonth(), fromDate.getUTCDate(), fromDate.getUTCHours(), fromDate.getUTCMinutes(), fromDate.getUTCSeconds(), fromDate.getUTCMilliseconds());
55
- }
56
- return fromDate;
57
- }
58
- const n = 'numeric';
59
- const s = 'short';
60
- const l = 'long';
61
- const dd = '2-digit';
62
- const STRFTIME = {
63
- // weekday
64
- '%A': { weekday: l },
65
- '%a': { weekday: s },
66
- // day
67
- '%d': { day: dd },
68
- '%-d': { day: n },
69
- // month
70
- '%m': { month: dd },
71
- '%-m': { month: n },
72
- '%B': { month: l },
73
- '%b': { month: s },
74
- '%bb': { month: n },
75
- // year
76
- '%y': { year: n },
77
- '%Y': { year: dd },
78
- // hour
79
- '%K': { hourCycle: 'h11', hour: dd },
80
- '%I': { hourCycle: 'h12', hour: dd },
81
- '%-I': { hourCycle: 'h12', hour: n },
82
- '%H': { hourCycle: 'h23', hour: dd },
83
- '%-H': { hourCycle: 'h23', hour: n },
84
- '%k': { hourCycle: 'h24', hour: n },
85
- // minutes
86
- '%M': { minute: dd },
87
- '%-M': { minute: n },
88
- // seconds
89
- '%S': { second: dd },
90
- '%-S': { second: n },
91
- // day period
92
- '%P': { dayPeriod: l },
93
- '%p': { dayPeriod: s },
94
- '%pp': { dayPeriod: 'narrow' },
95
- // era
96
- '%N': { era: l, year: dd },
97
- '%n': { era: s, year: dd },
98
- // timeZoneName
99
- // '%Z': { timeZoneName: 'longGeneric', year: dd },
100
- // '%-Z': { timeZoneName: 'shortGeneric', year: dd },
101
- '%z': { timeZoneName: 'longOffset', year: dd },
102
- '%-z': { timeZoneName: 'shortOffset', year: dd },
103
- '%Z': { timeZoneName: l, year: dd },
104
- '%-Z': { timeZoneName: s, year: dd }
105
- };
106
- const TOKENS = {
107
- // weekday
108
- dddd: { weekday: l },
109
- ddd: { weekday: s },
110
- E: { weekday: n },
111
- // day
112
- DD: { day: dd },
113
- D: { day: n },
114
- // month
115
- MM: { month: dd },
116
- M: { month: n },
117
- MMMM: { month: l },
118
- MMM: { month: s },
119
- // year
120
- YYYY: { year: n },
121
- YY: { year: dd },
122
- // hour
123
- hh: { hourCycle: 'h12', hour: dd },
124
- h: { hourCycle: 'h12', hour: n },
125
- HH: { hourCycle: 'h23', hour: dd },
126
- H: { hourCycle: 'h23', hour: n },
127
- kk: { hourCycle: 'h11', hour: dd },
128
- k: { hourCycle: 'h24', hour: n },
129
- // minutes
130
- mm: { minute: dd },
131
- m: { minute: n },
132
- // seconds
133
- ss: { second: dd },
134
- s: { second: n },
135
- // day period
136
- A: { dayPeriod: l },
137
- a: { dayPeriod: s },
138
- // era
139
- N: { era: s, year: dd },
140
- NN: { era: s, year: dd },
141
- NNN: { era: s, year: dd },
142
- NNNN: { era: l, year: dd },
143
- // timeZoneName
144
- zzz: { timeZoneName: l, year: dd },
145
- z: { timeZoneName: s, year: dd }
146
- };
147
- const HOUR_PARTS = { '%I': 1, '%-I': 1, '%K': 1, '%k': 1 };
148
- const ERA_PARTS = { '%n': 1, '%N': 1 };
149
- const TZ_PARTS = { '%-z': 1, '%z': 1, '%-Z': 1, '%Z': 1 };
150
- function formatter(locale, opts) {
151
- return new Intl.DateTimeFormat(locale, opts);
152
- }
153
- function formatHour(h, maxLength) {
154
- return String(h % 12 || 12).padStart(maxLength, '0');
155
- }
156
- function formatMeridiem(hour, isLowercase) {
157
- const m = hour < 12 ? 'AM' : 'PM';
158
- return isLowercase ? m.toLowerCase() : m;
159
- }
160
- function formatOrdinal(day, locale) {
161
- const rules = new Intl.PluralRules(locale, { type: 'ordinal' });
162
- const isEnglish = rules.resolvedOptions().locale.split('-')[0] === 'en';
163
- return isEnglish ? `${day}${ORDINAL_SUFFIXES[rules.select(day)]}` : String(day);
164
- }
165
- function formatPart(locale, opts, date, type) {
166
- return (formatter(locale, opts)
167
- .formatToParts(date)
168
- .find((part) => part.type === type)?.value ?? '');
169
- }
170
- /**
171
- * 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}.
172
- * @param {string} formatStr The format string to use
173
- * @param {Date} date The date value
174
- * @param {?string} locale The locale to use when formatting (default is system locale).
175
- * @see {@link https://momentjs.com/docs/#/displaying/format/ List of formats}
176
- * @example
177
- ```js
178
- formatDate('MM/DD/YYYY', new Date()) // '10/31/2022'
179
- ```
180
- */
181
- export function formatDate(formatStr, date, locale) {
182
- if (Number.isNaN(date.getTime()))
183
- return INVALID_DATE_STRING;
184
- const str = formatStr || FORMAT_DEFAULT;
185
- const zoneStr = padZoneStr(date);
186
- const time = {
187
- H: date.getHours(),
188
- HH: padStart(date.getHours(), 2, '0'),
189
- h: formatHour(date.getHours(), 1),
190
- hh: formatHour(date.getHours(), 2),
191
- a: formatMeridiem(date.getHours(), true),
192
- A: formatMeridiem(date.getHours()),
193
- m: date.getMinutes(),
194
- mm: padStart(date.getMinutes(), 2, '0'),
195
- s: date.getSeconds(),
196
- ss: padStart(date.getSeconds(), 2, '0'),
197
- SSS: padStart(date.getMilliseconds(), 3, '0'),
198
- X: Math.floor(date.getTime() / 1000),
199
- x: date.getTime()
200
- };
201
- const matches = {
202
- ...time,
203
- N: formatPart(locale, TOKENS.N, date, 'era'),
204
- NN: formatPart(locale, TOKENS.NN, date, 'era'),
205
- NNN: formatPart(locale, TOKENS.NNN, date, 'era'),
206
- NNNN: formatPart(locale, TOKENS.NNNN, date, 'era'),
207
- YY: padStart(Math.abs(date.getFullYear()) % 100, 2, '0'),
208
- YYYY: padYear(date.getFullYear()),
209
- M: date.getMonth() + 1,
210
- MM: padStart(date.getMonth() + 1, 2, '0'),
211
- MMM: formatter(locale, TOKENS.MMM).format(date),
212
- MMMM: formatter(locale, TOKENS.MMMM).format(date),
213
- Q: Math.ceil((date.getMonth() + 1) / 3),
214
- D: date.getDate(),
215
- DD: padStart(date.getDate(), 2, '0'),
216
- Do: formatOrdinal(date.getDate(), locale),
217
- d: date.getDay(),
218
- ddd: formatter(locale, TOKENS.ddd).format(date),
219
- dddd: formatter(locale, TOKENS.dddd).format(date),
220
- Z: zoneStr,
221
- ZZ: zoneStr.replace(':', ''),
222
- z: formatPart(locale, TOKENS.z, date, 'timeZoneName'),
223
- zzz: formatPart(locale, TOKENS.zzz, date, 'timeZoneName'),
224
- LT: `${time.h}:${time.mm} ${time.A}`,
225
- LTS: `${time.h}:${time.mm}:${time.ss} ${time.A}`,
226
- L: formatter(locale, DATE_SHORT_DD).format(date),
227
- LL: formatter(locale, DATE_FULL).format(date),
228
- LLL: formatter(locale, DATE_LONG_TIME).format(date),
229
- LLLL: formatter(locale, DATE_HUGE).format(date),
230
- l: formatter(locale, DATE_SHORT).format(date),
231
- ll: formatter(locale, DATE_MED).format(date),
232
- lll: formatter(locale, DATE_MED_TIME).format(date),
233
- llll: formatter(locale, DATE_MED_WITH_WEEKDAY).format(date)
234
- };
235
- return str.replace(REGEX_FORMAT, (match, $1) => $1 ?? matches[match] ?? match);
236
- }
237
- /**
238
- * Formats a date using a formatting string in the {@link https://strftime.org/ strftime} format, in any given locale.
239
- * @param {string} fmt The format string to apply
240
- * @param {Date} date The date value
241
- * @param {?string} locale The locale to use when formatting (default is system locale).
242
- * @returns {string} The string representation of date
243
- * @see {@link https://strftime.org/ strftime format}
244
- * @example
245
- ```js
246
- strftime('%A, %d/%m/%y', new Date())
247
- // 'Saturday, 01/02/2020'
248
- ```
249
- */
250
- export function strftime(fmt, date, locale) {
251
- if (date != null && Number.isNaN(+date))
252
- return INVALID_DATE_STRING;
253
- const results = [];
254
- let dayPeriod = '';
255
- const dayPeriodIndexes = [];
256
- for (let i = 0; i < fmt.length; i++) {
257
- let part = fmt[i];
258
- if (part === '%') {
259
- // check for escaped '%'
260
- if (fmt[++i] === '%') {
261
- results.push('%');
262
- continue;
263
- }
264
- if (fmt[i] === '-') {
265
- part += fmt[i++];
266
- }
267
- part += fmt[i] ?? '';
268
- // a doubled letter is a directive of its own only when the table lists it
269
- if (fmt[i + 1] === fmt[i] && STRFTIME[part + fmt[i]])
270
- part += fmt[++i];
271
- if (!STRFTIME[part]) {
272
- results.push(part);
273
- continue;
274
- }
275
- if (HOUR_PARTS[part]) {
276
- results.push(formatPart(locale, STRFTIME[part], date, 'hour'));
277
- // save the AM/PM for the correct spot
278
- dayPeriod = formatPart(locale, STRFTIME[part], date, 'dayPeriod');
279
- continue;
280
- }
281
- if (part === '%P' || part === '%p') {
282
- // leave this flag in place for later
283
- dayPeriodIndexes.push(results.length);
284
- results.push(part);
285
- continue;
286
- }
287
- if (ERA_PARTS[part] || TZ_PARTS[part]) {
288
- const type = ERA_PARTS[part] ? 'era' : 'timeZoneName';
289
- results.push(formatPart(locale, STRFTIME[part], date, type));
290
- continue;
291
- }
292
- // format any other parts, numbers without the unit text of the locale
293
- const [type, style] = Object.entries(STRFTIME[part]).at(-1);
294
- let res = style === n || style === dd
295
- ? formatPart(locale, STRFTIME[part], date, type)
296
- : formatter(locale, STRFTIME[part]).format(date);
297
- // fix bugs in time formatter
298
- if ((part === '%S' || part === '%M') && res.length === 1)
299
- res = `0${res}`;
300
- if (part === '%-H') {
301
- const hours = (date === undefined ? new Date() : new Date(date)).getHours();
302
- res = new Intl.NumberFormat(locale).format(hours);
303
- }
304
- results.push(res);
305
- }
306
- else {
307
- // output as literal
308
- results.push(part);
309
- }
310
- }
311
- // insert the AM/PM at the correct spots
312
- for (const index of dayPeriodIndexes) {
313
- results[index] = results[index] === '%p' ? dayPeriod.toLowerCase() : dayPeriod;
314
- }
315
- return results.join('').trim();
316
- }
317
- /** L: 09/04/1983 */
318
- const DATE_SHORT_DD = {
319
- year: n,
320
- month: dd,
321
- day: dd
322
- };
323
- /** l: 9/4/1983 */
324
- const DATE_SHORT = {
325
- year: n,
326
- month: n,
327
- day: n
328
- };
329
- /** ll: Oct 14, 1983 */
330
- const DATE_MED = {
331
- year: n,
332
- month: s,
333
- day: n
334
- };
335
- /** LL: October 14, 1983 */
336
- const DATE_FULL = {
337
- year: n,
338
- month: l,
339
- day: n
340
- };
341
- /** lll: Oct 14, 1983 8:30 PM */
342
- const DATE_MED_TIME = {
343
- year: n,
344
- month: s,
345
- day: n,
346
- hour: n,
347
- minute: n,
348
- hourCycle: 'h12'
349
- };
350
- /** LLL: October 14, 1983 8:30 PM */
351
- const DATE_LONG_TIME = {
352
- year: n,
353
- month: l,
354
- day: n,
355
- hour: n,
356
- minute: n,
357
- hourCycle: 'h12'
358
- };
359
- /** llll: Fri, Oct 14, 1983, 8:30 PM */
360
- const DATE_MED_WITH_WEEKDAY = {
361
- year: n,
362
- month: s,
363
- day: n,
364
- weekday: s,
365
- hour: n,
366
- minute: n,
367
- hourCycle: 'h12'
368
- };
369
- /** LLLL: Friday, October 14, 1983, 8:30 PM */
370
- const DATE_HUGE = {
371
- year: n,
372
- month: l,
373
- day: n,
374
- weekday: l,
375
- hour: n,
376
- minute: n,
377
- hourCycle: 'h12'
378
- };
@@ -1,9 +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 } from './duration.js';
9
- export type { DurationUnit, TDuration } from './duration.js';
@@ -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 } from './duration.js';
@@ -1,251 +0,0 @@
1
- /**
2
- * This module includes functions that deal with or produce iterators.
3
- *
4
- * @module itertools
5
- */
6
- import { add, type Comparer } from '../operators/index.js';
7
- import type { Function, Iteratee, Predicate } from '../types.js';
8
- /**
9
- * Make an iterator that returns accumulated sums, or accumulated results of other binary functions (specified via the optional `func` argument).
10
- * @param iterable The iterable to accumulate
11
- * @param func The accumulator function (default `add`).
12
- * @param initial Optional initial value (defaults to the first element in iterable)
13
- * @returns A sequence of accumulated values
14
- */
15
- export declare function accumulate<T>(iterable: Iterable<T>, func?: typeof add, initial?: any): Generator<T>;
16
- /**
17
- * Returns `true` when all of the items in iterable are truthy. An optional predicate function can be used to define what truthiness means for this specific collection.
18
- * @param iterable
19
- * @param fn
20
- * @returns `True` if all elements pass the test or are truthy else `false`.
21
- * @example
22
- ```js
23
- all([0])
24
- // false
25
-
26
- all([1, 2, 3])
27
- // true
28
-
29
- all([2, 4, 6], n => n > 1)
30
- // true
31
- ```
32
- @see {@link any}
33
- */
34
- export declare function all<T>(iterable: Iterable<T>, fn?: Predicate<T>): boolean;
35
- /**
36
- * Returns true when any of the items in iterable are truthy. An optional predicate function can be used to define what truthiness means for this specific collection.
37
- * @param iterable
38
- * @param fn
39
- * @returns `True` if any element passes the test or is truthy else `false`.
40
- * @example
41
- ```js
42
- any([0])
43
- // false
44
-
45
- any([0, 1, null, undefined])
46
- // true
47
-
48
- any([1, 4, 5], n => n % 2 === 0)
49
- // true
50
- ```
51
- @see {@link all}
52
- */
53
- export declare function any<T>(iterable: Iterable<T>, fn?: Predicate<T>): boolean;
54
- export declare function chain<T>(...iterables: Array<Iterable<T>>): Generator<T, void, unknown>;
55
- /**
56
- * Checks if the `value` is in `collection`.
57
- * @param collection The collection to inspect.
58
- * @param value The value to search for.
59
- * @returns Returns `true` if value is found, else `false`.
60
- * @example
61
- ```js
62
- contains([1, 2, 3], 1)
63
- // true
64
-
65
- contains({ 'a': 1, 'b': 2 }, 1)
66
- // true
67
-
68
- contains('abcd', 'bc')
69
- // true
70
- ```
71
- *
72
- * @see {@link collections.find}
73
- */
74
- export declare function contains(collection: Iterable<any>, value: any): boolean;
75
- /**
76
- * Returns a generator that drops elements from the iterable as long as the predicate is `true`; afterwards, returns every remaining element. Note, the generator does not produce any output until the predicate first becomes `false`.
77
- * @param iterable The iterable to inspect.
78
- * @param predicate A function invoked per element to check if it should be dropped.
79
- * @returns Elements
80
- */
81
- export declare function dropWhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Generator<T, T, unknown>;
82
- export declare function iforEach<T>(iterable: Iterable<T>, fun: Iteratee<T>): void;
83
- /**
84
- * Yields elements like `[index, item]` from an iterable. Index starts at zero by default.
85
- * @template T
86
- * @param iterable The iterable to inspect.
87
- * @param start The starting index.
88
- * @returns A generator with tuples like `[index, item]`.
89
- * @example
90
- ```js
91
- console.log([...enumerate(['hello', 'world'])])
92
- // [[0, 'hello'], [1, 'world']]
93
-
94
- // Start with index `1`
95
- console.log([...enumerate(['hello', 'world'], 1)])
96
- // [[1, 'hello'], [2, 'world']]
97
- ```
98
- */
99
- export declare function enumerate<T>(iterable: Iterable<T>, start?: number): Generator<[number, T], void, unknown>;
100
- /**
101
- * Returns the first element in an iterable.
102
- * @param iterable The iterable to inspect.
103
- * @returns The first element found or undefined if iterable is empty.
104
- */
105
- export declare function first<T>(iterable: Iterable<T>): T;
106
- /**
107
- * Creates a new generator that filters all falsy and empty values from iterable.
108
- * @param iterable The iterable to compact
109
- * @returns A generator with the filtered values.
110
- * @example
111
- ```js
112
- [...icompact([0, 1, false, 2, '', 3])]
113
- // [1, 2, 3]
114
- ```
115
- */
116
- export declare function icompact<T>(iterable: Iterable<T>): Generator<T, void, unknown>;
117
- /**
118
- * Iterates over elements of collection, producing only those elements where predicate returns a `truthy` value.
119
- */
120
- export declare function ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T, boolean>): Generator<T, void, unknown>;
121
- export declare function imap<T, TReturn = any>(iterable: Iterable<T>, mapFn: Predicate<T, TReturn>): Generator<TReturn, void, unknown>;
122
- /**
123
- * Returns a generator flattening one level of nesting in a list of lists.
124
- * @param iterables The iterable to flatten
125
- * @example
126
- ```js
127
- [...iflatten([[0, 1], [2, 3]])]
128
- // [0, 1, 2, 3]
129
- ```
130
- */
131
- export declare function iflatten<T = any>(iterables: Iterable<Iterable<T>>): Generator<T, void, unknown>;
132
- export declare function flatMap<T>(iterable: Iterable<T>, mapFn?: (x: T) => any): Generator<T, void, unknown>;
133
- export declare function islice<T>(iterable: Iterable<T>, start: number, stop?: number, step?: number): Generator<T, void, unknown>;
134
- export declare function itake<T>(n: number, iterable: Iterable<T>): Generator<T, void, unknown>;
135
- /**
136
- * Returns an Iterator from the elements of a collection or the object keys.
137
- * @param obj The given collection to iterate over.
138
- * @returns An Iterator type.
139
- */
140
- export declare function iter<T>(obj: any): Iterator<T, T>;
141
- export declare function partition<T>(iterable: Iterable<T>, predicate: Predicate<T, boolean>): [T[], T[]];
142
- /**
143
- * Returns a generator for a sequence of numbers in the given range, starting from `start` (default 0) to `stop` (not-inclusive) in increments of `step` (default 1).
144
- *
145
- * `range(x)` is a shorthand for `range(0, x, 1)`, or `range(0, x, -1)` when `x` is negative.
146
- * @param args When called with a single argument, it is assigned to `stop` param. If two arguments are given, it will assign them to `(start, stop)`. When three arguments, it means `(start, stop, step)`.
147
- * @example
148
- ```js
149
- range(5)
150
- // [0, 1, 2, 3, 4]
151
-
152
- range(2, 5)
153
- // [2, 3, 4]
154
-
155
- range(0, 5, 2)
156
- // [0, 2, 4]
157
-
158
- range(5, 0, -1)
159
- // [5, 4, 3, 2, 1]
160
-
161
- range(-3)
162
- // [0, -1, -2]
163
- ```
164
- */
165
- export declare function range(...args: number[]): Generator<number, void, unknown>;
166
- /**
167
- * Applies a `reducer` function on each element of the iterable, in order, passing the return value from the operation on the previous element. The final result of running the reducer across all elements of the iterable is a single value.
168
- * @param iterable The collection to reduce.
169
- * @param reducer A reducer function that will be called per item.
170
- * @param initial Optional initial value (defaults to the first element in the iterable).
171
- * @returns The result of calling reducer on each item.
172
- * @example
173
- ```js
174
- reduce([1, 2, 3, 4, 5], (x, y) => x + y, 0)
175
- // 15
176
- ```
177
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce Array.reduce()}
178
- */
179
- export declare function reduce<T>(iterable: Iterable<T>, reducer: (prev: T, value: T, index: any) => T, initial?: any): any;
180
- /**
181
- * Creates a new array with the elements from the iterable in reverse order.
182
- * @param iterable The iterable to inspect.
183
- * @returns A new array with the elements reversed.
184
- */
185
- export declare function reversed<T>(iterable: Iterable<T>): T[];
186
- /**
187
- * Creates a new sorted list from the elements in the array. This can be called many ways:
188
- * - sorted([...], true) - reverse order
189
- * - sorted([...], fn = x => any) - using a key fn
190
- * - sorted([...], fn = x => any, true) - reverse order using key
191
- * - sorted([...], false, (x, y) => number) - using custom compare
192
- * - sorted([...], fn = x => any, true, (x, y) => number) - custom key, reverse and compare
193
- *
194
- * If `args` is an Object, returns the sorted keys.
195
- *
196
- *
197
- * @param {(Array | Object)} args
198
- * @param {(boolean | Function)} [key]
199
- * @param {(boolean | Comparer)} [reverse]
200
- * @param {Comparer} [compareFn]
201
- * @return
202
- */
203
- export declare function sorted<T>(args: T[]): T[];
204
- export declare function sorted<T>(args: T[], reverse: boolean): T[];
205
- export declare function sorted<T>(args: T[], reverse: boolean, comp: Comparer): T[];
206
- export declare function sorted<T>(args: T[], key: Function): T[];
207
- export declare function sorted<T>(args: T[], key: Function, reverse: boolean): T[];
208
- /**
209
- * Sort `args` in place. Can be called like this:
210
- * - sort([...], true) - reverse order
211
- * - sort([...], (x, y) => number) - using custom compare
212
- * - sort([...], true, (x, y) => number) - reverse and using custom compare
213
- *
214
- * @param {any[]} args
215
- * @param {(boolean | Comparer)} [reverse]
216
- * @param {Comparer} [compareFn]
217
- * @return
218
- */
219
- export declare function sort<T>(args: T[]): T[];
220
- export declare function sort<T>(args: T[], reverse: boolean): T[];
221
- export declare function sort<T>(args: T[], compareFn: Comparer): T[];
222
- export declare function sort<T>(args: T[], reverse: boolean, compareFn: Comparer): T[];
223
- export declare function take<T>(n: number, iterable: Iterable<T>): T[];
224
- /**
225
- * Returns a generator that takes elements from the iterable as long as the predicate is `true`.
226
- * @param iterable The iterable to inspect.
227
- * @param predicate A function invoked per element to check if it should be taken.
228
- * @returns Elements
229
- */
230
- export declare function takeWhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Generator<T, void, unknown>;
231
- /** Returns a generator that calls `fn(index)` for each index < n */
232
- /**
233
- * Returns a generator that produces `fn(index)` for each `index < n`.
234
- * @param n The number of times to invoke `fn`.
235
- * @param fn A function used to produce the results.
236
- */
237
- export declare function times(n: number, fn: (index: number) => any): Generator<any, void, unknown>;
238
- /**
239
- * Returns a generator that aggregates elements from the iterables producing tuples with the next element from each one.
240
- * @param args The iterables to zip
241
- * @returns Tuples with elements from each iterator
242
- * @example
243
- ```js
244
- for item of zip([1, 2, 3], ['sugar', 'spice', 'nice'])
245
- console.log(item)
246
- // [1, 'sugar']
247
- // [2, 'spice']
248
- // [3, 'nice']
249
- ```
250
- */
251
- export declare function zip(...args: Array<Iterable<any>>): Generator<any[], void, unknown>;