@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.
package/README.md CHANGED
@@ -31,7 +31,7 @@ deno add jsr:@bytebury/toolkit
31
31
 
32
32
  ```ts
33
33
  function sayHelloTo(name: string): void {
34
- if (isWhitespace(name) {
34
+ if ((isWhitespace(name)) {
35
35
  console.log("Hello, Guest!");
36
36
  } else {
37
37
  console.log(`Hello, ${title(name)}!`);
@@ -42,7 +42,7 @@ function getAverageAge(): number {
42
42
  const people = [
43
43
  { name: "Tom", age: 2 },
44
44
  { name: "Carly", age: 8 },
45
- { name: "Jenny", age: 5 }
45
+ { name: "Jenny", age: 5 },
46
46
  ];
47
47
  return average(people.map(({ age }) => age)); // 5
48
48
  }
package/esm/mod.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from "./src/core.js";
2
2
  export * from "./src/dates.js";
3
3
  export * from "./src/duration.js";
4
4
  export * from "./src/numbers.js";
5
+ export * from "./src/objects.js";
5
6
  export * from "./src/strings.js";
6
7
  export * from "./src/utility_types.js";
7
8
  //# sourceMappingURL=mod.d.ts.map
package/esm/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC"}
package/esm/mod.js CHANGED
@@ -2,5 +2,6 @@ export * from "./src/core.js";
2
2
  export * from "./src/dates.js";
3
3
  export * from "./src/duration.js";
4
4
  export * from "./src/numbers.js";
5
+ export * from "./src/objects.js";
5
6
  export * from "./src/strings.js";
6
7
  export * from "./src/utility_types.js";
package/esm/src/core.d.ts CHANGED
@@ -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;;;;;;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,GAAG,MAAM,EAAE,CAS5E;AAED;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,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"}
package/esm/src/core.js CHANGED
@@ -223,21 +223,7 @@ export function distinct(list) {
223
223
  * ```
224
224
  */
225
225
  export function sample(list) {
226
- return list[random(0, list.length)];
227
- }
228
- /**
229
- * Gives a random number in the given range. The first parameter is inclusive
230
- * and the second one is exclusive. Therefore, it will work with lists out of
231
- * the box.
232
- *
233
- * @example
234
- * ```ts
235
- * rand(0, 10); // 0 -> 9
236
- * rand(3, 7); // 3 -> 6
237
- * ```
238
- */
239
- export function random(start, end) {
240
- return Math.floor(Math.random() * (end - start)) + start;
226
+ return list[Math.floor(Math.random() * list.length)];
241
227
  }
242
228
  /**
243
229
  * Determines if the given value is truthy.
@@ -293,6 +279,24 @@ export function isSome(thing) {
293
279
  export function isNone(thing) {
294
280
  return thing === null || thing === undefined;
295
281
  }
282
+ /**
283
+ * Determines if the given value is an array. Acts as a type guard, narrowing
284
+ * the value to `unknown[]` in branches where the result is `true`.
285
+ *
286
+ * @remarks alias for `Array.isArray`.
287
+ *
288
+ * @example
289
+ * ```ts
290
+ * isArray([]); // true
291
+ * isArray([1, 2, 3]); // true
292
+ * isArray("hello"); // false
293
+ * isArray(null); // false
294
+ * isArray({}); // false
295
+ * ```
296
+ */
297
+ export function isArray(thing) {
298
+ return Array.isArray(thing);
299
+ }
296
300
  /**
297
301
  * Returns a function that does nothing.
298
302
  *
@@ -321,20 +325,6 @@ export function noop() {
321
325
  export function todo(message) {
322
326
  noop();
323
327
  }
324
- /**
325
- * Returns true if the given value is within the given range.
326
- *
327
- * @example
328
- * ```ts
329
- * inRange(5, 0, 10); // true
330
- * inRange(0, 0, 10); // true
331
- * inRange(10, 0, 10); // true
332
- * inRange(11, 0, 10); // false
333
- * ```
334
- */
335
- export function inRange(value, min, max) {
336
- return value >= min && value <= max;
337
- }
338
328
  /**
339
329
  * Splits an array into chunks of a fixed size.
340
330
  *
@@ -466,3 +456,197 @@ export function includesAny(searchIn, searchFor) {
466
456
  const terms = Array.isArray(searchFor) ? searchFor : [searchFor];
467
457
  return terms.some((term) => searchIn.includes(term));
468
458
  }
459
+ /**
460
+ * Returns a new array with elements removed and/or inserted, without mutating the original.
461
+ *
462
+ * @param list - The source array
463
+ * @param start - Index at which to start changing the array
464
+ * @param deleteCount - Number of elements to remove
465
+ * @param items - Elements to insert at the start index
466
+ * @returns A new array with the modifications applied
467
+ *
468
+ * @example
469
+ * ```ts
470
+ * splice([1, 2, 3, 4], 1, 2) // [1, 4]
471
+ * splice([1, 2, 3], 1, 0, [9, 10]) // [1, 9, 10, 2, 3]
472
+ * splice([1, 2, 3, 4], 2) // [1, 2] — omitting deleteCount removes from start to end
473
+ * ```
474
+ */
475
+ export function splice(list, start, deleteCount, items = []) {
476
+ const copy = [...list];
477
+ copy.splice(start, deleteCount ?? list.length, ...items);
478
+ return copy;
479
+ }
480
+ /**
481
+ * Groups items into a `Map` keyed by the value returned from `keyFn`.
482
+ *
483
+ * @example
484
+ * ```ts
485
+ * groupBy([1, 2, 3, 4], (n) => n % 2 === 0 ? "even" : "odd");
486
+ * // Map { "odd" => [1, 3], "even" => [2, 4] }
487
+ *
488
+ * const people = [{ role: "admin", name: "A" }, { role: "user", name: "B" }];
489
+ * groupBy(people, (p) => p.role);
490
+ * // Map { "admin" => [{...}], "user" => [{...}] }
491
+ * ```
492
+ */
493
+ export function groupBy(list, keyFn) {
494
+ const result = new Map();
495
+ for (const item of list) {
496
+ const key = keyFn(item);
497
+ const existing = result.get(key);
498
+ if (existing)
499
+ existing.push(item);
500
+ else
501
+ result.set(key, [item]);
502
+ }
503
+ return result;
504
+ }
505
+ /**
506
+ * Splits a list into two: the first contains items where the predicate is true,
507
+ * the second contains items where it is false.
508
+ *
509
+ * @example
510
+ * ```ts
511
+ * partition([1, 2, 3, 4], (n) => n % 2 === 0); // [[2, 4], [1, 3]]
512
+ * ```
513
+ */
514
+ export function partition(list, predicate) {
515
+ const pass = [];
516
+ const fail = [];
517
+ for (const item of list) {
518
+ if (predicate(item))
519
+ pass.push(item);
520
+ else
521
+ fail.push(item);
522
+ }
523
+ return [pass, fail];
524
+ }
525
+ /**
526
+ * Returns a new array sorted by the value returned from `keyFn`.
527
+ *
528
+ * @remarks
529
+ * Does not mutate the input list.
530
+ *
531
+ * @example
532
+ * ```ts
533
+ * sortBy([{ age: 30 }, { age: 20 }], (p) => p.age); // [{ age: 20 }, { age: 30 }]
534
+ * sortBy(["banana", "apple", "cherry"], (s) => s); // ["apple", "banana", "cherry"]
535
+ * ```
536
+ */
537
+ export function sortBy(list, keyFn) {
538
+ return [...list].sort((a, b) => {
539
+ const aKey = keyFn(a);
540
+ const bKey = keyFn(b);
541
+ if (aKey < bKey)
542
+ return -1;
543
+ if (aKey > bKey)
544
+ return 1;
545
+ return 0;
546
+ });
547
+ }
548
+ /**
549
+ * Removes `null` and `undefined` values from a list.
550
+ *
551
+ * @example
552
+ * ```ts
553
+ * compact([1, null, 2, undefined, 3]); // [1, 2, 3]
554
+ * compact(["a", "", null, "b"]); // ["a", "", "b"]
555
+ * ```
556
+ */
557
+ export function compact(list) {
558
+ return list.filter(isSome);
559
+ }
560
+ /**
561
+ * Generates a list of numbers in the given range. The start is inclusive,
562
+ * the end is exclusive.
563
+ *
564
+ * @example
565
+ * ```ts
566
+ * range(0, 5); // [0, 1, 2, 3, 4]
567
+ * range(2, 8, 2); // [2, 4, 6]
568
+ * range(5, 0, -1); // [5, 4, 3, 2, 1]
569
+ * ```
570
+ */
571
+ export function range(start, end, step = 1) {
572
+ if (step === 0)
573
+ throw new Error("range step must not be 0");
574
+ const result = [];
575
+ if (step > 0) {
576
+ for (let i = start; i < end; i += step)
577
+ result.push(i);
578
+ }
579
+ else {
580
+ for (let i = start; i > end; i += step)
581
+ result.push(i);
582
+ }
583
+ return result;
584
+ }
585
+ /**
586
+ * Pairs up elements from two lists. Stops at the shorter list.
587
+ *
588
+ * @example
589
+ * ```ts
590
+ * zip([1, 2, 3], ["a", "b", "c"]); // [[1, "a"], [2, "b"], [3, "c"]]
591
+ * zip([1, 2, 3], ["a"]); // [[1, "a"]]
592
+ * ```
593
+ */
594
+ export function zip(a, b) {
595
+ const length = Math.min(a.length, b.length);
596
+ const result = [];
597
+ for (let i = 0; i < length; i++)
598
+ result.push([a[i], b[i]]);
599
+ return result;
600
+ }
601
+ /**
602
+ * Returns the first `n` elements of a list. Does not mutate the input.
603
+ *
604
+ * @example
605
+ * ```ts
606
+ * take([1, 2, 3, 4], 2); // [1, 2]
607
+ * take([1, 2], 5); // [1, 2]
608
+ * take([1, 2, 3], 0); // []
609
+ * ```
610
+ */
611
+ export function take(list, n) {
612
+ return list.slice(0, Math.max(0, n));
613
+ }
614
+ /**
615
+ * Returns a list with the first `n` elements removed. Does not mutate the input.
616
+ *
617
+ * @example
618
+ * ```ts
619
+ * drop([1, 2, 3, 4], 2); // [3, 4]
620
+ * drop([1, 2], 5); // []
621
+ * ```
622
+ */
623
+ export function drop(list, n) {
624
+ return list.slice(Math.max(0, n));
625
+ }
626
+ /**
627
+ * Returns a new list with the elements at indices `i` and `j` swapped.
628
+ *
629
+ * @example
630
+ * ```ts
631
+ * swap([1, 2, 3, 4], 0, 3); // [4, 2, 3, 1]
632
+ * ```
633
+ */
634
+ export function swap(list, i, j) {
635
+ const copy = [...list];
636
+ [copy[i], copy[j]] = [copy[j], copy[i]];
637
+ return copy;
638
+ }
639
+ /**
640
+ * Returns a new list with an element moved from one index to another.
641
+ *
642
+ * @example
643
+ * ```ts
644
+ * move([1, 2, 3, 4], 0, 2); // [2, 3, 1, 4]
645
+ * ```
646
+ */
647
+ export function move(list, from, to) {
648
+ const copy = [...list];
649
+ const [item] = copy.splice(from, 1);
650
+ copy.splice(to, 0, item);
651
+ return copy;
652
+ }
@@ -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":["../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H,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE5C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE9C;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE7C;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE7C;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE5C;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE9C;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE3C;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE/C;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE9C"}
package/esm/src/dates.js CHANGED
@@ -27,6 +27,18 @@ export function tomorrow() {
27
27
  export function yesterday() {
28
28
  return subtractDays(today(), 1);
29
29
  }
30
+ /**
31
+ * The current month as a number from 1 (January) to 12 (December).
32
+ */
33
+ export function currentMonth() {
34
+ return now().getMonth() + 1;
35
+ }
36
+ /**
37
+ * The current year as a number (e.g. 2026).
38
+ */
39
+ export function currentYear() {
40
+ return now().getFullYear();
41
+ }
30
42
  /**
31
43
  * Adds the given amount of days to the specified date.
32
44
  */
@@ -195,3 +207,21 @@ export function isInFuture(date) {
195
207
  export function isToday(date) {
196
208
  return !isInFuture(date) && !isInPast(date);
197
209
  }
210
+ /**
211
+ * Determines if the date is yesterday.
212
+ *
213
+ * @remarks
214
+ * this is date specific. Time of day is ignored.
215
+ */
216
+ export function isYesterday(date) {
217
+ return date >= yesterday() && date < today();
218
+ }
219
+ /**
220
+ * Determines if the date is tomorrow.
221
+ *
222
+ * @remarks
223
+ * this is date specific. Time of day is ignored.
224
+ */
225
+ export function isTomorrow(date) {
226
+ return date >= tomorrow() && date < addDays(tomorrow(), 1);
227
+ }
@@ -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,EAAE,MAAM,GAAG,OAAO,CAE1C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiB9C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAG1C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAG1C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAG1C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAG9C"}
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,EAAE,MAAM,GAAG,OAAO,CAE1C;AAED;;;;;;;;;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