@bytebury/toolkit 1.8.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.
@@ -220,18 +220,6 @@ export declare function distinct<T>(list: T[]): T[];
220
220
  * ```
221
221
  */
222
222
  export declare function sample<T>(list: T[]): T | undefined;
223
- /**
224
- * Gives a random number in the given range. The first parameter is inclusive
225
- * and the second one is exclusive. Therefore, it will work with lists out of
226
- * the box.
227
- *
228
- * @example
229
- * ```ts
230
- * rand(0, 10); // 0 -> 9
231
- * rand(3, 7); // 3 -> 6
232
- * ```
233
- */
234
- export declare function random(start: number, end: number): number;
235
223
  /**
236
224
  * Determines if the given value is truthy.
237
225
  *
@@ -278,6 +266,22 @@ export declare function isSome(thing: unknown): boolean;
278
266
  * ```
279
267
  */
280
268
  export declare function isNone(thing: unknown): boolean;
269
+ /**
270
+ * Determines if the given value is an array. Acts as a type guard, narrowing
271
+ * the value to `unknown[]` in branches where the result is `true`.
272
+ *
273
+ * @remarks alias for `Array.isArray`.
274
+ *
275
+ * @example
276
+ * ```ts
277
+ * isArray([]); // true
278
+ * isArray([1, 2, 3]); // true
279
+ * isArray("hello"); // false
280
+ * isArray(null); // false
281
+ * isArray({}); // false
282
+ * ```
283
+ */
284
+ export declare function isArray(thing: unknown): thing is unknown[];
281
285
  /**
282
286
  * Returns a function that does nothing.
283
287
  *
@@ -301,18 +305,6 @@ export declare function noop(): void;
301
305
  * ```
302
306
  */
303
307
  export declare function todo(message?: string): void;
304
- /**
305
- * Returns true if the given value is within the given range.
306
- *
307
- * @example
308
- * ```ts
309
- * inRange(5, 0, 10); // true
310
- * inRange(0, 0, 10); // true
311
- * inRange(10, 0, 10); // true
312
- * inRange(11, 0, 10); // false
313
- * ```
314
- */
315
- export declare function inRange(value: number, min: number, max: number): boolean;
316
308
  /**
317
309
  * Splits an array into chunks of a fixed size.
318
310
  *
@@ -409,4 +401,129 @@ export declare function includes(searchIn: string | string[] | null | undefined,
409
401
  * ```
410
402
  */
411
403
  export declare function includesAny(searchIn: string | string[] | null | undefined, searchFor: string | string[] | null | undefined): boolean;
404
+ /**
405
+ * Returns a new array with elements removed and/or inserted, without mutating the original.
406
+ *
407
+ * @param list - The source array
408
+ * @param start - Index at which to start changing the array
409
+ * @param deleteCount - Number of elements to remove
410
+ * @param items - Elements to insert at the start index
411
+ * @returns A new array with the modifications applied
412
+ *
413
+ * @example
414
+ * ```ts
415
+ * splice([1, 2, 3, 4], 1, 2) // [1, 4]
416
+ * splice([1, 2, 3], 1, 0, [9, 10]) // [1, 9, 10, 2, 3]
417
+ * splice([1, 2, 3, 4], 2) // [1, 2] — omitting deleteCount removes from start to end
418
+ * ```
419
+ */
420
+ export declare function splice<T>(list: T[], start: number, deleteCount?: number, items?: T[]): T[];
421
+ /**
422
+ * Groups items into a `Map` keyed by the value returned from `keyFn`.
423
+ *
424
+ * @example
425
+ * ```ts
426
+ * groupBy([1, 2, 3, 4], (n) => n % 2 === 0 ? "even" : "odd");
427
+ * // Map { "odd" => [1, 3], "even" => [2, 4] }
428
+ *
429
+ * const people = [{ role: "admin", name: "A" }, { role: "user", name: "B" }];
430
+ * groupBy(people, (p) => p.role);
431
+ * // Map { "admin" => [{...}], "user" => [{...}] }
432
+ * ```
433
+ */
434
+ export declare function groupBy<T, K>(list: T[], keyFn: (item: T) => K): Map<K, T[]>;
435
+ /**
436
+ * Splits a list into two: the first contains items where the predicate is true,
437
+ * the second contains items where it is false.
438
+ *
439
+ * @example
440
+ * ```ts
441
+ * partition([1, 2, 3, 4], (n) => n % 2 === 0); // [[2, 4], [1, 3]]
442
+ * ```
443
+ */
444
+ export declare function partition<T>(list: T[], predicate: (item: T) => boolean): [T[], T[]];
445
+ /**
446
+ * Returns a new array sorted by the value returned from `keyFn`.
447
+ *
448
+ * @remarks
449
+ * Does not mutate the input list.
450
+ *
451
+ * @example
452
+ * ```ts
453
+ * sortBy([{ age: 30 }, { age: 20 }], (p) => p.age); // [{ age: 20 }, { age: 30 }]
454
+ * sortBy(["banana", "apple", "cherry"], (s) => s); // ["apple", "banana", "cherry"]
455
+ * ```
456
+ */
457
+ export declare function sortBy<T>(list: T[], keyFn: (item: T) => number | string): T[];
458
+ /**
459
+ * Removes `null` and `undefined` values from a list.
460
+ *
461
+ * @example
462
+ * ```ts
463
+ * compact([1, null, 2, undefined, 3]); // [1, 2, 3]
464
+ * compact(["a", "", null, "b"]); // ["a", "", "b"]
465
+ * ```
466
+ */
467
+ export declare function compact<T>(list: (T | null | undefined)[]): T[];
468
+ /**
469
+ * Generates a list of numbers in the given range. The start is inclusive,
470
+ * the end is exclusive.
471
+ *
472
+ * @example
473
+ * ```ts
474
+ * range(0, 5); // [0, 1, 2, 3, 4]
475
+ * range(2, 8, 2); // [2, 4, 6]
476
+ * range(5, 0, -1); // [5, 4, 3, 2, 1]
477
+ * ```
478
+ */
479
+ export declare function range(start: number, end: number, step?: number): number[];
480
+ /**
481
+ * Pairs up elements from two lists. Stops at the shorter list.
482
+ *
483
+ * @example
484
+ * ```ts
485
+ * zip([1, 2, 3], ["a", "b", "c"]); // [[1, "a"], [2, "b"], [3, "c"]]
486
+ * zip([1, 2, 3], ["a"]); // [[1, "a"]]
487
+ * ```
488
+ */
489
+ export declare function zip<A, B>(a: A[], b: B[]): [A, B][];
490
+ /**
491
+ * Returns the first `n` elements of a list. Does not mutate the input.
492
+ *
493
+ * @example
494
+ * ```ts
495
+ * take([1, 2, 3, 4], 2); // [1, 2]
496
+ * take([1, 2], 5); // [1, 2]
497
+ * take([1, 2, 3], 0); // []
498
+ * ```
499
+ */
500
+ export declare function take<T>(list: T[], n: number): T[];
501
+ /**
502
+ * Returns a list with the first `n` elements removed. Does not mutate the input.
503
+ *
504
+ * @example
505
+ * ```ts
506
+ * drop([1, 2, 3, 4], 2); // [3, 4]
507
+ * drop([1, 2], 5); // []
508
+ * ```
509
+ */
510
+ export declare function drop<T>(list: T[], n: number): T[];
511
+ /**
512
+ * Returns a new list with the elements at indices `i` and `j` swapped.
513
+ *
514
+ * @example
515
+ * ```ts
516
+ * swap([1, 2, 3, 4], 0, 3); // [4, 2, 3, 1]
517
+ * ```
518
+ */
519
+ export declare function swap<T>(list: T[], i: number, j: number): T[];
520
+ /**
521
+ * Returns a new list with an element moved from one index to another.
522
+ *
523
+ * @example
524
+ * ```ts
525
+ * move([1, 2, 3, 4], 0, 2); // [2, 3, 1, 4]
526
+ * ```
527
+ */
528
+ export declare function move<T>(list: T[], from: number, to: number): T[];
412
529
  //# sourceMappingURL=core.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/src/core.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAElC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAEjE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AACzD,wBAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AAKnD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AACxD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AAKlD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAEpE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAK3E;AAED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AAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAKlD;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAEjD;AAED;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAEjD;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAI5D;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,CAAC,EAAE,CAKhE"}
@@ -15,20 +15,30 @@ exports.isNotEmpty = isNotEmpty;
15
15
  exports.unique = unique;
16
16
  exports.distinct = distinct;
17
17
  exports.sample = sample;
18
- exports.random = random;
19
18
  exports.truthy = truthy;
20
19
  exports.falsy = falsy;
21
20
  exports.isSome = isSome;
22
21
  exports.isNone = isNone;
22
+ exports.isArray = isArray;
23
23
  exports.noop = noop;
24
24
  exports.todo = todo;
25
- exports.inRange = inRange;
26
25
  exports.chunk = chunk;
27
26
  exports.union = union;
28
27
  exports.difference = difference;
29
28
  exports.intersection = intersection;
30
29
  exports.includes = includes;
31
30
  exports.includesAny = includesAny;
31
+ exports.splice = splice;
32
+ exports.groupBy = groupBy;
33
+ exports.partition = partition;
34
+ exports.sortBy = sortBy;
35
+ exports.compact = compact;
36
+ exports.range = range;
37
+ exports.zip = zip;
38
+ exports.take = take;
39
+ exports.drop = drop;
40
+ exports.swap = swap;
41
+ exports.move = move;
32
42
  const strings_js_1 = require("./strings.js");
33
43
  /**
34
44
  * Clone an object using structuredClone.
@@ -254,21 +264,7 @@ function distinct(list) {
254
264
  * ```
255
265
  */
256
266
  function sample(list) {
257
- return list[random(0, list.length)];
258
- }
259
- /**
260
- * Gives a random number in the given range. The first parameter is inclusive
261
- * and the second one is exclusive. Therefore, it will work with lists out of
262
- * the box.
263
- *
264
- * @example
265
- * ```ts
266
- * rand(0, 10); // 0 -> 9
267
- * rand(3, 7); // 3 -> 6
268
- * ```
269
- */
270
- function random(start, end) {
271
- return Math.floor(Math.random() * (end - start)) + start;
267
+ return list[Math.floor(Math.random() * list.length)];
272
268
  }
273
269
  /**
274
270
  * Determines if the given value is truthy.
@@ -324,6 +320,24 @@ function isSome(thing) {
324
320
  function isNone(thing) {
325
321
  return thing === null || thing === undefined;
326
322
  }
323
+ /**
324
+ * Determines if the given value is an array. Acts as a type guard, narrowing
325
+ * the value to `unknown[]` in branches where the result is `true`.
326
+ *
327
+ * @remarks alias for `Array.isArray`.
328
+ *
329
+ * @example
330
+ * ```ts
331
+ * isArray([]); // true
332
+ * isArray([1, 2, 3]); // true
333
+ * isArray("hello"); // false
334
+ * isArray(null); // false
335
+ * isArray({}); // false
336
+ * ```
337
+ */
338
+ function isArray(thing) {
339
+ return Array.isArray(thing);
340
+ }
327
341
  /**
328
342
  * Returns a function that does nothing.
329
343
  *
@@ -352,20 +366,6 @@ function noop() {
352
366
  function todo(message) {
353
367
  noop();
354
368
  }
355
- /**
356
- * Returns true if the given value is within the given range.
357
- *
358
- * @example
359
- * ```ts
360
- * inRange(5, 0, 10); // true
361
- * inRange(0, 0, 10); // true
362
- * inRange(10, 0, 10); // true
363
- * inRange(11, 0, 10); // false
364
- * ```
365
- */
366
- function inRange(value, min, max) {
367
- return value >= min && value <= max;
368
- }
369
369
  /**
370
370
  * Splits an array into chunks of a fixed size.
371
371
  *
@@ -497,3 +497,197 @@ function includesAny(searchIn, searchFor) {
497
497
  const terms = Array.isArray(searchFor) ? searchFor : [searchFor];
498
498
  return terms.some((term) => searchIn.includes(term));
499
499
  }
500
+ /**
501
+ * Returns a new array with elements removed and/or inserted, without mutating the original.
502
+ *
503
+ * @param list - The source array
504
+ * @param start - Index at which to start changing the array
505
+ * @param deleteCount - Number of elements to remove
506
+ * @param items - Elements to insert at the start index
507
+ * @returns A new array with the modifications applied
508
+ *
509
+ * @example
510
+ * ```ts
511
+ * splice([1, 2, 3, 4], 1, 2) // [1, 4]
512
+ * splice([1, 2, 3], 1, 0, [9, 10]) // [1, 9, 10, 2, 3]
513
+ * splice([1, 2, 3, 4], 2) // [1, 2] — omitting deleteCount removes from start to end
514
+ * ```
515
+ */
516
+ function splice(list, start, deleteCount, items = []) {
517
+ const copy = [...list];
518
+ copy.splice(start, deleteCount ?? list.length, ...items);
519
+ return copy;
520
+ }
521
+ /**
522
+ * Groups items into a `Map` keyed by the value returned from `keyFn`.
523
+ *
524
+ * @example
525
+ * ```ts
526
+ * groupBy([1, 2, 3, 4], (n) => n % 2 === 0 ? "even" : "odd");
527
+ * // Map { "odd" => [1, 3], "even" => [2, 4] }
528
+ *
529
+ * const people = [{ role: "admin", name: "A" }, { role: "user", name: "B" }];
530
+ * groupBy(people, (p) => p.role);
531
+ * // Map { "admin" => [{...}], "user" => [{...}] }
532
+ * ```
533
+ */
534
+ function groupBy(list, keyFn) {
535
+ const result = new Map();
536
+ for (const item of list) {
537
+ const key = keyFn(item);
538
+ const existing = result.get(key);
539
+ if (existing)
540
+ existing.push(item);
541
+ else
542
+ result.set(key, [item]);
543
+ }
544
+ return result;
545
+ }
546
+ /**
547
+ * Splits a list into two: the first contains items where the predicate is true,
548
+ * the second contains items where it is false.
549
+ *
550
+ * @example
551
+ * ```ts
552
+ * partition([1, 2, 3, 4], (n) => n % 2 === 0); // [[2, 4], [1, 3]]
553
+ * ```
554
+ */
555
+ function partition(list, predicate) {
556
+ const pass = [];
557
+ const fail = [];
558
+ for (const item of list) {
559
+ if (predicate(item))
560
+ pass.push(item);
561
+ else
562
+ fail.push(item);
563
+ }
564
+ return [pass, fail];
565
+ }
566
+ /**
567
+ * Returns a new array sorted by the value returned from `keyFn`.
568
+ *
569
+ * @remarks
570
+ * Does not mutate the input list.
571
+ *
572
+ * @example
573
+ * ```ts
574
+ * sortBy([{ age: 30 }, { age: 20 }], (p) => p.age); // [{ age: 20 }, { age: 30 }]
575
+ * sortBy(["banana", "apple", "cherry"], (s) => s); // ["apple", "banana", "cherry"]
576
+ * ```
577
+ */
578
+ function sortBy(list, keyFn) {
579
+ return [...list].sort((a, b) => {
580
+ const aKey = keyFn(a);
581
+ const bKey = keyFn(b);
582
+ if (aKey < bKey)
583
+ return -1;
584
+ if (aKey > bKey)
585
+ return 1;
586
+ return 0;
587
+ });
588
+ }
589
+ /**
590
+ * Removes `null` and `undefined` values from a list.
591
+ *
592
+ * @example
593
+ * ```ts
594
+ * compact([1, null, 2, undefined, 3]); // [1, 2, 3]
595
+ * compact(["a", "", null, "b"]); // ["a", "", "b"]
596
+ * ```
597
+ */
598
+ function compact(list) {
599
+ return list.filter(isSome);
600
+ }
601
+ /**
602
+ * Generates a list of numbers in the given range. The start is inclusive,
603
+ * the end is exclusive.
604
+ *
605
+ * @example
606
+ * ```ts
607
+ * range(0, 5); // [0, 1, 2, 3, 4]
608
+ * range(2, 8, 2); // [2, 4, 6]
609
+ * range(5, 0, -1); // [5, 4, 3, 2, 1]
610
+ * ```
611
+ */
612
+ function range(start, end, step = 1) {
613
+ if (step === 0)
614
+ throw new Error("range step must not be 0");
615
+ const result = [];
616
+ if (step > 0) {
617
+ for (let i = start; i < end; i += step)
618
+ result.push(i);
619
+ }
620
+ else {
621
+ for (let i = start; i > end; i += step)
622
+ result.push(i);
623
+ }
624
+ return result;
625
+ }
626
+ /**
627
+ * Pairs up elements from two lists. Stops at the shorter list.
628
+ *
629
+ * @example
630
+ * ```ts
631
+ * zip([1, 2, 3], ["a", "b", "c"]); // [[1, "a"], [2, "b"], [3, "c"]]
632
+ * zip([1, 2, 3], ["a"]); // [[1, "a"]]
633
+ * ```
634
+ */
635
+ function zip(a, b) {
636
+ const length = Math.min(a.length, b.length);
637
+ const result = [];
638
+ for (let i = 0; i < length; i++)
639
+ result.push([a[i], b[i]]);
640
+ return result;
641
+ }
642
+ /**
643
+ * Returns the first `n` elements of a list. Does not mutate the input.
644
+ *
645
+ * @example
646
+ * ```ts
647
+ * take([1, 2, 3, 4], 2); // [1, 2]
648
+ * take([1, 2], 5); // [1, 2]
649
+ * take([1, 2, 3], 0); // []
650
+ * ```
651
+ */
652
+ function take(list, n) {
653
+ return list.slice(0, Math.max(0, n));
654
+ }
655
+ /**
656
+ * Returns a list with the first `n` elements removed. Does not mutate the input.
657
+ *
658
+ * @example
659
+ * ```ts
660
+ * drop([1, 2, 3, 4], 2); // [3, 4]
661
+ * drop([1, 2], 5); // []
662
+ * ```
663
+ */
664
+ function drop(list, n) {
665
+ return list.slice(Math.max(0, n));
666
+ }
667
+ /**
668
+ * Returns a new list with the elements at indices `i` and `j` swapped.
669
+ *
670
+ * @example
671
+ * ```ts
672
+ * swap([1, 2, 3, 4], 0, 3); // [4, 2, 3, 1]
673
+ * ```
674
+ */
675
+ function swap(list, i, j) {
676
+ const copy = [...list];
677
+ [copy[i], copy[j]] = [copy[j], copy[i]];
678
+ return copy;
679
+ }
680
+ /**
681
+ * Returns a new list with an element moved from one index to another.
682
+ *
683
+ * @example
684
+ * ```ts
685
+ * move([1, 2, 3, 4], 0, 2); // [2, 3, 1, 4]
686
+ * ```
687
+ */
688
+ function move(list, from, to) {
689
+ const copy = [...list];
690
+ const [item] = copy.splice(from, 1);
691
+ copy.splice(to, 0, item);
692
+ return copy;
693
+ }
@@ -14,6 +14,14 @@ export declare function tomorrow(): Date;
14
14
  * Yesterday's date at midnight.
15
15
  */
16
16
  export declare function yesterday(): Date;
17
+ /**
18
+ * The current month as a number from 1 (January) to 12 (December).
19
+ */
20
+ export declare function currentMonth(): number;
21
+ /**
22
+ * The current year as a number (e.g. 2026).
23
+ */
24
+ export declare function currentYear(): number;
17
25
  /**
18
26
  * Adds the given amount of days to the specified date.
19
27
  */
@@ -110,4 +118,18 @@ export declare function isInFuture(date: Date): boolean;
110
118
  * Determines if the date is today.
111
119
  */
112
120
  export declare function isToday(date: Date): boolean;
121
+ /**
122
+ * Determines if the date is yesterday.
123
+ *
124
+ * @remarks
125
+ * this is date specific. Time of day is ignored.
126
+ */
127
+ export declare function isYesterday(date: Date): boolean;
128
+ /**
129
+ * Determines if the date is tomorrow.
130
+ *
131
+ * @remarks
132
+ * this is date specific. Time of day is ignored.
133
+ */
134
+ export declare function isTomorrow(date: Date): boolean;
113
135
  //# sourceMappingURL=dates.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../../src/src/dates.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,GAAG,IAAI,IAAI,CAE1B;AAED;;GAEG;AACH,wBAAgB,KAAK,IAAI,IAAI,CAI5B;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,IAAI,CAI/B;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,IAAI,CAEhC;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAItD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAE3D;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAW1D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAE/D;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAExD;AAED;;GAEG;AACH,wBAAgB,aAA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.yesterday = yesterday;
7
+ exports.currentMonth = currentMonth;
8
+ exports.currentYear = currentYear;
7
9
  exports.addDays = addDays;
8
10
  exports.subtractDays = subtractDays;
9
11
  exports.addMonths = addMonths;
@@ -25,6 +27,8 @@ exports.isWeekday = isWeekday;
25
27
  exports.isInPast = isInPast;
26
28
  exports.isInFuture = isInFuture;
27
29
  exports.isToday = isToday;
30
+ exports.isYesterday = isYesterday;
31
+ exports.isTomorrow = isTomorrow;
28
32
  const duration_js_1 = require("./duration.js");
29
33
  /**
30
34
  * Right now. This is an alias for `new Date()`.
@@ -54,6 +58,18 @@ function tomorrow() {
54
58
  function yesterday() {
55
59
  return subtractDays(today(), 1);
56
60
  }
61
+ /**
62
+ * The current month as a number from 1 (January) to 12 (December).
63
+ */
64
+ function currentMonth() {
65
+ return now().getMonth() + 1;
66
+ }
67
+ /**
68
+ * The current year as a number (e.g. 2026).
69
+ */
70
+ function currentYear() {
71
+ return now().getFullYear();
72
+ }
57
73
  /**
58
74
  * Adds the given amount of days to the specified date.
59
75
  */
@@ -222,3 +238,21 @@ function isInFuture(date) {
222
238
  function isToday(date) {
223
239
  return !isInFuture(date) && !isInPast(date);
224
240
  }
241
+ /**
242
+ * Determines if the date is yesterday.
243
+ *
244
+ * @remarks
245
+ * this is date specific. Time of day is ignored.
246
+ */
247
+ function isYesterday(date) {
248
+ return date >= yesterday() && date < today();
249
+ }
250
+ /**
251
+ * Determines if the date is tomorrow.
252
+ *
253
+ * @remarks
254
+ * this is date specific. Time of day is ignored.
255
+ */
256
+ function isTomorrow(date) {
257
+ return date >= tomorrow() && date < addDays(tomorrow(), 1);
258
+ }
@@ -139,4 +139,67 @@ export declare function sum(nums: number[]): number;
139
139
  * ```
140
140
  */
141
141
  export declare function average(nums: number[]): number;
142
+ /**
143
+ * Clamps a number between a minimum and maximum value.
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * clamp(5, 0, 10); // 5
148
+ * clamp(-1, 0, 10); // 0
149
+ * clamp(15, 0, 10); // 10
150
+ * ```
151
+ */
152
+ export declare function clamp(num: number, min: number, max: number): number;
153
+ /**
154
+ * Returns the median value from a list of numbers.
155
+ *
156
+ * @remarks
157
+ * If you pass an empty list, this will return `0`.
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * median([]); // 0
162
+ * median([1, 2, 3]); // 2
163
+ * median([1, 2, 3, 4]); // 2.5
164
+ * ```
165
+ */
166
+ export declare function median(nums: number[]): number;
167
+ /**
168
+ * Rounds a number to the given number of decimal places.
169
+ *
170
+ * @remarks
171
+ * This is `null | undefined` safe. If you pass `null | undefined` this will return `0`.
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * roundTo(1.235, 2); // 1.24
176
+ * roundTo(1.5, 0); // 2
177
+ * roundTo(1234.5, -2); // 1200
178
+ * ```
179
+ */
180
+ export declare function roundTo(num: number, decimals: number): number;
181
+ /**
182
+ * Gives a random number in the given range. The first parameter is inclusive
183
+ * and the second one is exclusive. Therefore, it will work with lists out of
184
+ * the box.
185
+ *
186
+ * @example
187
+ * ```ts
188
+ * random(0, 10); // 0 -> 9
189
+ * random(3, 7); // 3 -> 6
190
+ * ```
191
+ */
192
+ export declare function random(start: number, end: number): number;
193
+ /**
194
+ * Returns true if the given value is within the given range (inclusive on both ends).
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * inRange(5, 0, 10); // true
199
+ * inRange(0, 0, 10); // true
200
+ * inRange(10, 0, 10); // true
201
+ * inRange(11, 0, 10); // false
202
+ * ```
203
+ */
204
+ export declare function inRange(value: number, min: number, max: number): boolean;
142
205
  //# sourceMappingURL=numbers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../src/src/numbers.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE3C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,KAAK,CAAC,GAAG,E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