atomic-fns 1.1.6 → 1.2.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 (51) hide show
  1. package/README.md +51 -12
  2. package/dist/collections/BTree.d.ts +11 -10
  3. package/dist/collections/BTree.js +58 -80
  4. package/dist/collections/Heap.d.ts +2 -2
  5. package/dist/collections/Heap.js +1 -1
  6. package/dist/collections/LRUCache.d.ts +8 -5
  7. package/dist/collections/LRUCache.js +24 -11
  8. package/dist/collections/SortedMap.d.ts +4 -4
  9. package/dist/collections/SortedMap.js +4 -3
  10. package/dist/collections/SortedSet.d.ts +2 -2
  11. package/dist/collections/SortedTree.d.ts +9 -9
  12. package/dist/collections/SortedTree.js +7 -6
  13. package/dist/collections/SplayTree.d.ts +17 -15
  14. package/dist/collections/SplayTree.js +42 -29
  15. package/dist/collections/Trie.d.ts +2 -2
  16. package/dist/collections/Trie.js +26 -26
  17. package/dist/collections/deque.d.ts +11 -11
  18. package/dist/collections/deque.js +17 -10
  19. package/dist/collections/frozenset.js +4 -1
  20. package/dist/collections/index.d.ts +30 -48
  21. package/dist/collections/index.js +210 -82
  22. package/dist/decimal/index.d.ts +7 -5
  23. package/dist/decimal/index.js +63 -28
  24. package/dist/functools/index.d.ts +10 -34
  25. package/dist/functools/index.js +25 -57
  26. package/dist/globals/index.d.ts +5 -22
  27. package/dist/globals/index.js +24 -40
  28. package/dist/i18n/currency.d.ts +10 -7
  29. package/dist/i18n/currency.js +22 -7
  30. package/dist/i18n/date/index.d.ts +22 -16
  31. package/dist/i18n/date/index.js +89 -67
  32. package/dist/i18n/date/utils.d.ts +6 -7
  33. package/dist/i18n/date/utils.js +15 -113
  34. package/dist/i18n/duration.d.ts +13 -12
  35. package/dist/i18n/duration.js +38 -32
  36. package/dist/i18n/format.d.ts +10 -2
  37. package/dist/i18n/format.js +100 -217
  38. package/dist/i18n/index.d.ts +2 -1
  39. package/dist/itertools/index.d.ts +21 -25
  40. package/dist/itertools/index.js +41 -44
  41. package/dist/math/index.d.ts +12 -29
  42. package/dist/math/index.js +16 -33
  43. package/dist/mod.d.ts +1 -0
  44. package/dist/mod.js +1 -0
  45. package/dist/operators/index.d.ts +3 -3
  46. package/dist/operators/index.js +62 -38
  47. package/dist/random/index.js +9 -6
  48. package/dist/string/index.d.ts +1 -1
  49. package/dist/string/index.js +2 -4
  50. package/dist/types.d.ts +3 -3
  51. package/package.json +16 -21
@@ -1,15 +1,33 @@
1
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;
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;
4
3
  const FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ';
5
- const padStart = (string, length, pad) => String(string).padStart(length, pad);
6
- const padZoneStr = (instance) => {
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) {
7
13
  const negMinutes = -instance.getTimezoneOffset();
8
14
  const minutes = Math.abs(negMinutes);
9
15
  const hourOffset = Math.floor(minutes / 60);
10
16
  const minuteOffset = minutes % 60;
11
- return `${negMinutes <= 0 ? '+' : '-'}${padStart(hourOffset, 2, '0')}:${padStart(minuteOffset, 2, '0')}`;
12
- };
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
+ }
13
31
  /**
14
32
  * Returns a new Date from the given arguments.
15
33
  * @param {string | number | Date} date The date value
@@ -27,22 +45,13 @@ export function asDate(date, utc = false) {
27
45
  const d = date.match(NATIVE_DATE);
28
46
  if (d) {
29
47
  const m = d[2] - 1 || 0;
30
- const ms = (d[7] || '0').slice(0, 3);
31
- if (utc) {
32
- return new Date(Date.UTC(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms));
33
- }
34
- return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms);
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);
35
50
  }
36
51
  }
37
52
  const fromDate = new Date(date);
38
53
  if (utc) {
39
- fromDate.setFullYear(fromDate.getUTCFullYear());
40
- fromDate.setMonth(fromDate.getUTCMonth());
41
- fromDate.setDate(fromDate.getUTCDate());
42
- fromDate.setHours(fromDate.getUTCHours());
43
- fromDate.setMinutes(fromDate.getUTCMinutes());
44
- fromDate.setSeconds(fromDate.getUTCSeconds());
45
- fromDate.setMilliseconds(fromDate.getUTCMilliseconds());
54
+ return fromFields(false, fromDate.getUTCFullYear(), fromDate.getUTCMonth(), fromDate.getUTCDate(), fromDate.getUTCHours(), fromDate.getUTCMinutes(), fromDate.getUTCSeconds(), fromDate.getUTCMilliseconds());
46
55
  }
47
56
  return fromDate;
48
57
  }
@@ -54,7 +63,6 @@ const STRFTIME = {
54
63
  // weekday
55
64
  '%A': { weekday: l },
56
65
  '%a': { weekday: s },
57
- '%aa': { weekday: n },
58
66
  // day
59
67
  '%d': { day: dd },
60
68
  '%-d': { day: n },
@@ -87,7 +95,6 @@ const STRFTIME = {
87
95
  // era
88
96
  '%N': { era: l, year: dd },
89
97
  '%n': { era: s, year: dd },
90
- '%nn': { era: n, year: 'narrow' },
91
98
  // timeZoneName
92
99
  // '%Z': { timeZoneName: 'longGeneric', year: dd },
93
100
  // '%-Z': { timeZoneName: 'shortGeneric', year: dd },
@@ -134,34 +141,46 @@ const TOKENS = {
134
141
  NNN: { era: s, year: dd },
135
142
  NNNN: { era: l, year: dd },
136
143
  // timeZoneName
137
- ZZ: { timeZoneName: 'longOffset', year: dd },
138
- Z: { timeZoneName: 'shortOffset', year: dd },
139
144
  zzz: { timeZoneName: l, year: dd },
140
145
  z: { timeZoneName: s, year: dd }
141
146
  };
142
147
  const HOUR_PARTS = { '%I': 1, '%-I': 1, '%K': 1, '%k': 1 };
143
- const ERA_PARTS = { '%n': 1, '%N': 1, '%nn': 1 };
144
- const TZ_PARTS = { '%ZZ': 1, '%-ZZ': 1, '%-z': 1, '%z': 1, '%-Z': 1, '%Z': 1 };
145
- const formatter = (locale, opts) => new Intl.DateTimeFormat(locale, opts);
146
- const formatHour = (h, maxLength) => String(h % 12 || 12).padStart(maxLength, '0');
147
- const formatMeridiem = (hour, isLowercase) => {
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) {
148
157
  const m = hour < 12 ? 'AM' : 'PM';
149
158
  return isLowercase ? m.toLowerCase() : m;
150
- };
151
- const formatPart = (locale, t, date) => {
152
- const value = formatter(locale, TOKENS[t]).format(date);
153
- return value.split(/\s+/g).slice(1).join(' ');
154
- };
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
+ }
155
170
  /**
156
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}.
157
- * @param {string} str The format string to use
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).
158
175
  * @see {@link https://momentjs.com/docs/#/displaying/format/ List of formats}
159
176
  * @example
160
177
  ```js
161
- formatDate(new Date(), 'MM/DD/YYYY') // '10/31/2022'
178
+ formatDate('MM/DD/YYYY', new Date()) // '10/31/2022'
162
179
  ```
163
180
  */
164
181
  export function formatDate(formatStr, date, locale) {
182
+ if (Number.isNaN(date.getTime()))
183
+ return INVALID_DATE_STRING;
165
184
  const str = formatStr || FORMAT_DEFAULT;
166
185
  const zoneStr = padZoneStr(date);
167
186
  const time = {
@@ -181,12 +200,12 @@ export function formatDate(formatStr, date, locale) {
181
200
  };
182
201
  const matches = {
183
202
  ...time,
184
- N: formatPart(locale, 'N', date),
185
- NN: formatPart(locale, 'NN', date),
186
- NNN: formatPart(locale, 'NNN', date),
187
- NNNN: formatPart(locale, 'NNNN', date),
188
- YY: String(date.getFullYear()).slice(-2),
189
- YYYY: date.getFullYear(),
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()),
190
209
  M: date.getMonth() + 1,
191
210
  MM: padStart(date.getMonth() + 1, 2, '0'),
192
211
  MMM: formatter(locale, TOKENS.MMM).format(date),
@@ -194,13 +213,14 @@ export function formatDate(formatStr, date, locale) {
194
213
  Q: Math.ceil((date.getMonth() + 1) / 3),
195
214
  D: date.getDate(),
196
215
  DD: padStart(date.getDate(), 2, '0'),
216
+ Do: formatOrdinal(date.getDate(), locale),
197
217
  d: date.getDay(),
198
218
  ddd: formatter(locale, TOKENS.ddd).format(date),
199
219
  dddd: formatter(locale, TOKENS.dddd).format(date),
200
- Z: formatPart(locale, 'Z', date),
201
- ZZ: formatPart(locale, 'ZZ', date),
202
- z: formatPart(locale, 'z', date),
203
- zzz: formatPart(locale, 'zzz', date),
220
+ Z: zoneStr,
221
+ ZZ: zoneStr.replace(':', ''),
222
+ z: formatPart(locale, TOKENS.z, date, 'timeZoneName'),
223
+ zzz: formatPart(locale, TOKENS.zzz, date, 'timeZoneName'),
204
224
  LT: `${time.h}:${time.mm} ${time.A}`,
205
225
  LTS: `${time.h}:${time.mm}:${time.ss} ${time.A}`,
206
226
  L: formatter(locale, DATE_SHORT_DD).format(date),
@@ -212,7 +232,7 @@ export function formatDate(formatStr, date, locale) {
212
232
  lll: formatter(locale, DATE_MED_TIME).format(date),
213
233
  llll: formatter(locale, DATE_MED_WITH_WEEKDAY).format(date)
214
234
  };
215
- return str.replace(REGEX_FORMAT, (match, $1) => $1 || matches[match] || zoneStr.replace(':', '')); // 'ZZ'
235
+ return str.replace(REGEX_FORMAT, (match, $1) => $1 ?? matches[match] ?? match);
216
236
  }
217
237
  /**
218
238
  * Formats a date using a formatting string in the {@link https://strftime.org/ strftime} format, in any given locale.
@@ -221,11 +241,18 @@ export function formatDate(formatStr, date, locale) {
221
241
  * @param {?string} locale The locale to use when formatting (default is system locale).
222
242
  * @returns {string} The string representation of date
223
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
+ ```
224
249
  */
225
250
  export function strftime(fmt, date, locale) {
251
+ if (date != null && Number.isNaN(+date))
252
+ return INVALID_DATE_STRING;
226
253
  const results = [];
227
254
  let dayPeriod = '';
228
- let dayPeriodIndex = -1;
255
+ const dayPeriodIndexes = [];
229
256
  for (let i = 0; i < fmt.length; i++) {
230
257
  let part = fmt[i];
231
258
  if (part === '%') {
@@ -237,37 +264,43 @@ export function strftime(fmt, date, locale) {
237
264
  if (fmt[i] === '-') {
238
265
  part += fmt[i++];
239
266
  }
240
- part += fmt[i];
241
- // add any repeated characters that come after
242
- while (i < fmt.length - 1 && fmt[i + 1] === fmt[i])
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]])
243
270
  part += fmt[++i];
271
+ if (!STRFTIME[part]) {
272
+ results.push(part);
273
+ continue;
274
+ }
244
275
  if (HOUR_PARTS[part]) {
245
- const res = formatter(locale, STRFTIME[part]).format(date).split(/\s+/g);
276
+ results.push(formatPart(locale, STRFTIME[part], date, 'hour'));
246
277
  // save the AM/PM for the correct spot
247
- results.push(res[0]);
248
- dayPeriod = res[1];
278
+ dayPeriod = formatPart(locale, STRFTIME[part], date, 'dayPeriod');
249
279
  continue;
250
280
  }
251
281
  if (part === '%P' || part === '%p') {
252
282
  // leave this flag in place for later
253
- dayPeriodIndex = results.length;
254
- if (part === '%p' && dayPeriod) {
255
- dayPeriod = dayPeriod.toLowerCase();
256
- }
283
+ dayPeriodIndexes.push(results.length);
257
284
  results.push(part);
258
285
  continue;
259
286
  }
260
287
  if (ERA_PARTS[part] || TZ_PARTS[part]) {
261
- // the formatting includes the date/year so we take what comes after
262
- const res = formatter(locale, STRFTIME[part]).format(date).split(/\s+/g);
263
- results.push(res.slice(1).join(' '));
288
+ const type = ERA_PARTS[part] ? 'era' : 'timeZoneName';
289
+ results.push(formatPart(locale, STRFTIME[part], date, type));
264
290
  continue;
265
291
  }
266
- // format any other parts
267
- let res = formatter(locale, STRFTIME[part]).format(date);
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);
268
297
  // fix bugs in time formatter
269
298
  if ((part === '%S' || part === '%M') && res.length === 1)
270
- res = '0' + res;
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
+ }
271
304
  results.push(res);
272
305
  }
273
306
  else {
@@ -275,12 +308,12 @@ export function strftime(fmt, date, locale) {
275
308
  results.push(part);
276
309
  }
277
310
  }
278
- // insert the AM/PM at the correct spot
279
- if (dayPeriodIndex >= 0)
280
- results[dayPeriodIndex] = dayPeriod || '';
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
+ }
281
315
  return results.join('').trim();
282
316
  }
283
- const DATETIME_DEFAULT = {};
284
317
  /** L: 09/04/1983 */
285
318
  const DATE_SHORT_DD = {
286
319
  year: n,
@@ -333,7 +366,7 @@ const DATE_MED_WITH_WEEKDAY = {
333
366
  minute: n,
334
367
  hourCycle: 'h12'
335
368
  };
336
- /** LLLL: Tuesday, October 14, 1983, 8:30 PM */
369
+ /** LLLL: Friday, October 14, 1983, 8:30 PM */
337
370
  const DATE_HUGE = {
338
371
  year: n,
339
372
  month: l,
@@ -343,153 +376,3 @@ const DATE_HUGE = {
343
376
  minute: n,
344
377
  hourCycle: 'h12'
345
378
  };
346
- /** LT: 09:30 AM */
347
- const TIME_SIMPLE = {
348
- hour: n,
349
- minute: n,
350
- hourCycle: 'h12'
351
- };
352
- /** LTS: 09:30:23 AM */
353
- const TIME_WITH_SECONDS = {
354
- hour: n,
355
- minute: n,
356
- second: n,
357
- hourCycle: 'h12'
358
- };
359
- /** 09:30:23 AM EDT */
360
- const TIME_WITH_SHORT_OFFSET = {
361
- hour: n,
362
- minute: n,
363
- second: n,
364
- timeZoneName: s,
365
- hourCycle: 'h12'
366
- };
367
- /** 09:30:23 AM Eastern Daylight Time */
368
- const TIME_WITH_LONG_OFFSET = {
369
- hour: n,
370
- minute: n,
371
- second: n,
372
- timeZoneName: l,
373
- hourCycle: 'h12'
374
- };
375
- /** 09:30 */
376
- const TIME_24_SIMPLE = {
377
- hour: n,
378
- minute: n,
379
- hourCycle: 'h23'
380
- };
381
- /** 09:30:23 */
382
- const TIME_24_WITH_SECONDS = {
383
- hour: n,
384
- minute: n,
385
- second: n,
386
- hourCycle: 'h23'
387
- };
388
- /** 09:30:23 EDT */
389
- const TIME_24_WITH_SHORT_OFFSET = {
390
- hour: n,
391
- minute: n,
392
- second: n,
393
- hourCycle: 'h23',
394
- timeZoneName: s
395
- };
396
- /** 09:30:23 Eastern Daylight Time */
397
- const TIME_24_WITH_LONG_OFFSET = {
398
- hour: n,
399
- minute: n,
400
- second: n,
401
- hourCycle: 'h23',
402
- timeZoneName: l
403
- };
404
- /** 10/14/1983, 9:30 AM */
405
- const DATETIME_SHORT = {
406
- year: n,
407
- month: n,
408
- day: n,
409
- hour: n,
410
- minute: n,
411
- hourCycle: 'h12'
412
- };
413
- /** 10/14/1983, 9:30:33 AM */
414
- const DATETIME_SHORT_WITH_SECONDS = {
415
- year: n,
416
- month: n,
417
- day: n,
418
- hour: n,
419
- minute: n,
420
- second: n,
421
- hourCycle: 'h12'
422
- };
423
- /** Oct 14, 1983, 9:30 AM */
424
- const DATETIME_MED = {
425
- year: n,
426
- month: s,
427
- day: n,
428
- hour: n,
429
- minute: n,
430
- hourCycle: 'h12'
431
- };
432
- /** Oct 14, 1983, 9:30:33 AM */
433
- const DATETIME_MED_WITH_SECONDS = {
434
- year: n,
435
- month: s,
436
- day: n,
437
- hour: n,
438
- minute: n,
439
- second: n,
440
- hourCycle: 'h12'
441
- };
442
- /** Fri, 14 Oct 1983, 9:30 AM */
443
- const DATETIME_MED_WITH_WEEKDAY = {
444
- year: n,
445
- month: s,
446
- day: n,
447
- weekday: s,
448
- hour: n,
449
- minute: n,
450
- hourCycle: 'h12'
451
- };
452
- /** October 14, 1983, 9:30 AM EDT */
453
- const DATETIME_FULL = {
454
- year: n,
455
- month: l,
456
- day: n,
457
- hour: n,
458
- minute: n,
459
- timeZoneName: s,
460
- hourCycle: 'h12'
461
- };
462
- /** October 14, 1983, 9:30:33 AM EDT */
463
- const DATETIME_FULL_WITH_SECONDS = {
464
- year: n,
465
- month: l,
466
- day: n,
467
- hour: n,
468
- minute: n,
469
- second: n,
470
- timeZoneName: s,
471
- hourCycle: 'h12'
472
- };
473
- /** Friday, October 14, 1983, 9:30 AM Eastern Daylight Time */
474
- const DATETIME_HUGE = {
475
- year: n,
476
- month: l,
477
- day: n,
478
- weekday: l,
479
- hour: n,
480
- minute: n,
481
- timeZoneName: l,
482
- hourCycle: 'h12'
483
- };
484
- /** Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time */
485
- const DATETIME_HUGE_WITH_SECONDS = {
486
- year: n,
487
- month: l,
488
- day: n,
489
- weekday: l,
490
- hour: n,
491
- minute: n,
492
- second: n,
493
- timeZoneName: l,
494
- hourCycle: 'h12'
495
- };
@@ -5,4 +5,5 @@
5
5
  */
6
6
  export * from './currency.js';
7
7
  export * from './date/index.js';
8
- export { Duration, TDuration, DurationUnit } from './duration.js';
8
+ export { Duration } from './duration.js';
9
+ export type { DurationUnit, TDuration } from './duration.js';
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * @module itertools
5
5
  */
6
- import { add, Comparer } from '../operators/index.js';
7
- import { Function, Iteratee, Predicate } from '../types';
6
+ import { add, type Comparer } from '../operators/index.js';
7
+ import type { Function, Iteratee, Predicate } from '../types.js';
8
8
  /**
9
9
  * Make an iterator that returns accumulated sums, or accumulated results of other binary functions (specified via the optional `func` argument).
10
10
  * @param iterable The iterable to accumulate
@@ -12,7 +12,7 @@ import { Function, Iteratee, Predicate } from '../types';
12
12
  * @param initial Optional initial value (defaults to the first element in iterable)
13
13
  * @returns A sequence of accumulated values
14
14
  */
15
- export declare function accumulate<T>(iterable: Iterable<T>, func?: typeof add, initial?: any): Generator<any, void, unknown>;
15
+ export declare function accumulate<T>(iterable: Iterable<T>, func?: typeof add, initial?: any): Generator<T>;
16
16
  /**
17
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
18
  * @param iterable
@@ -21,12 +21,12 @@ export declare function accumulate<T>(iterable: Iterable<T>, func?: typeof add,
21
21
  * @example
22
22
  ```js
23
23
  all([0])
24
- // true
24
+ // false
25
25
 
26
26
  all([1, 2, 3])
27
27
  // true
28
28
 
29
- all([2, 4, 6] => (n) => n > 1)
29
+ all([2, 4, 6], n => n > 1)
30
30
  // true
31
31
  ```
32
32
  @see {@link any}
@@ -45,7 +45,7 @@ any([0])
45
45
  any([0, 1, null, undefined])
46
46
  // true
47
47
 
48
- any([1, 4, 5] => (n) => n % 2 === 0)
48
+ any([1, 4, 5], n => n % 2 === 0)
49
49
  // true
50
50
  ```
51
51
  @see {@link all}
@@ -62,9 +62,6 @@ export declare function chain<T>(...iterables: Array<Iterable<T>>): Generator<T,
62
62
  contains([1, 2, 3], 1)
63
63
  // true
64
64
 
65
- contains([1, 2, 3], 1, 2)
66
- // false
67
-
68
65
  contains({ 'a': 1, 'b': 2 }, 1)
69
66
  // true
70
67
 
@@ -74,7 +71,7 @@ contains('abcd', 'bc')
74
71
  *
75
72
  * @see {@link collections.find}
76
73
  */
77
- export declare function contains(collection: Iterable<any>, value: any): any;
74
+ export declare function contains(collection: Iterable<any>, value: any): boolean;
78
75
  /**
79
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`.
80
77
  * @param iterable The iterable to inspect.
@@ -83,7 +80,6 @@ export declare function contains(collection: Iterable<any>, value: any): any;
83
80
  */
84
81
  export declare function dropWhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Generator<T, T, unknown>;
85
82
  export declare function iforEach<T>(iterable: Iterable<T>, fun: Iteratee<T>): void;
86
- export declare function IterableIterator<T = any>(next: Iterator<T>['next']): Iterable<T> & Iterator<T>;
87
83
  /**
88
84
  * Yields elements like `[index, item]` from an iterable. Index starts at zero by default.
89
85
  * @template T
@@ -109,11 +105,11 @@ export declare function enumerate<T>(iterable: Iterable<T>, start?: number): Gen
109
105
  export declare function first<T>(iterable: Iterable<T>): T;
110
106
  /**
111
107
  * Creates a new generator that filters all falsy and empty values from iterable.
112
- * @param arr The array to compact
113
- * @returns A new array with the filtered values.
108
+ * @param iterable The iterable to compact
109
+ * @returns A generator with the filtered values.
114
110
  * @example
115
111
  ```js
116
- compact([0, 1, false, 2, '', 3])
112
+ [...icompact([0, 1, false, 2, '', 3])]
117
113
  // [1, 2, 3]
118
114
  ```
119
115
  */
@@ -134,7 +130,7 @@ export declare function imap<T, TReturn = any>(iterable: Iterable<T>, mapFn: Pre
134
130
  */
135
131
  export declare function iflatten<T = any>(iterables: Iterable<Iterable<T>>): Generator<T, void, unknown>;
136
132
  export declare function flatMap<T>(iterable: Iterable<T>, mapFn?: (x: T) => any): Generator<T, void, unknown>;
137
- export declare function islice<T>(iterable: Iterable<T>, start: number, stop?: number, step?: number): Generator<T, T, unknown>;
133
+ export declare function islice<T>(iterable: Iterable<T>, start: number, stop?: number, step?: number): Generator<T, void, unknown>;
138
134
  export declare function itake<T>(n: number, iterable: Iterable<T>): Generator<T, void, unknown>;
139
135
  /**
140
136
  * Returns an Iterator from the elements of a collection or the object keys.
@@ -146,7 +142,7 @@ export declare function partition<T>(iterable: Iterable<T>, predicate: Predicate
146
142
  /**
147
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).
148
144
  *
149
- * `range(x)` is a shorthand for `range(0, x, 1)`.
145
+ * `range(x)` is a shorthand for `range(0, x, 1)`, or `range(0, x, -1)` when `x` is negative.
150
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)`.
151
147
  * @example
152
148
  ```js
@@ -163,7 +159,7 @@ range(5, 0, -1)
163
159
  // [5, 4, 3, 2, 1]
164
160
 
165
161
  range(-3)
166
- // []
162
+ // [0, -1, -2]
167
163
  ```
168
164
  */
169
165
  export declare function range(...args: number[]): Generator<number, void, unknown>;
@@ -189,11 +185,11 @@ export declare function reduce<T>(iterable: Iterable<T>, reducer: (prev: T, valu
189
185
  export declare function reversed<T>(iterable: Iterable<T>): T[];
190
186
  /**
191
187
  * Creates a new sorted list from the elements in the array. This can be called many ways:
192
- * - sorted([...], true) => reverse order
193
- * - sorted([...], fn = (x) => any) => using a key fn
194
- * - sorted([...], fn = (x) => any, true) => reverse order using key
195
- * - sorted([...], false, (x, y) => number) => using custom compare
196
- * - sorted([...], fn = (x) => any, true, (x, y) => number) => custom key, reverse and compare
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
197
193
  *
198
194
  * If `args` is an Object, returns the sorted keys.
199
195
  *
@@ -211,9 +207,9 @@ export declare function sorted<T>(args: T[], key: Function): T[];
211
207
  export declare function sorted<T>(args: T[], key: Function, reverse: boolean): T[];
212
208
  /**
213
209
  * Sort `args` in place. Can be called like this:
214
- * - sort([...], true) => reverse order
215
- * - sort([...], (x, y) => number) => using custom compare
216
- * - sort([...], true, (x, y) => number) => reverse and using custom compare
210
+ * - sort([...], true) - reverse order
211
+ * - sort([...], (x, y) => number) - using custom compare
212
+ * - sort([...], true, (x, y) => number) - reverse and using custom compare
217
213
  *
218
214
  * @param {any[]} args
219
215
  * @param {(boolean | Comparer)} [reverse]