@bytebury/toolkit 1.9.0 → 2.1.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 (52) hide show
  1. package/README.md +11 -2
  2. package/esm/deps/jsr.io/@std/internal/{1.0.13 → 1.0.14}/build_message.d.ts.map +1 -1
  3. package/{script/deps/jsr.io/@std/internal/1.0.13 → esm/deps/jsr.io/@std/internal/1.0.14}/diff.d.ts.map +1 -1
  4. package/{script/deps/jsr.io/@std/internal/1.0.13 → esm/deps/jsr.io/@std/internal/1.0.14}/diff_str.d.ts.map +1 -1
  5. package/{script/deps/jsr.io/@std/internal/1.0.13 → esm/deps/jsr.io/@std/internal/1.0.14}/format.d.ts.map +1 -1
  6. package/esm/deps/jsr.io/@std/internal/{1.0.13 → 1.0.14}/styles.d.ts.map +1 -1
  7. package/esm/deps/jsr.io/@std/internal/{1.0.13 → 1.0.14}/types.d.ts.map +1 -1
  8. package/esm/mod.d.ts +1 -0
  9. package/esm/mod.d.ts.map +1 -1
  10. package/esm/mod.js +1 -0
  11. package/esm/src/core.d.ts +151 -26
  12. package/esm/src/core.d.ts.map +1 -1
  13. package/esm/src/core.js +226 -30
  14. package/esm/src/dates.d.ts +14 -0
  15. package/esm/src/dates.d.ts.map +1 -1
  16. package/esm/src/dates.js +18 -0
  17. package/esm/src/numbers.d.ts +63 -0
  18. package/esm/src/numbers.d.ts.map +1 -1
  19. package/esm/src/numbers.js +80 -0
  20. package/esm/src/objects.d.ts +90 -0
  21. package/esm/src/objects.d.ts.map +1 -0
  22. package/esm/src/objects.js +129 -0
  23. package/esm/src/objects_test.d.ts.map +1 -0
  24. package/esm/src/strings.d.ts +70 -0
  25. package/esm/src/strings.d.ts.map +1 -1
  26. package/esm/src/strings.js +93 -0
  27. package/package.json +30 -1
  28. package/script/deps/jsr.io/@std/internal/{1.0.13 → 1.0.14}/build_message.d.ts.map +1 -1
  29. package/{esm/deps/jsr.io/@std/internal/1.0.13 → script/deps/jsr.io/@std/internal/1.0.14}/diff.d.ts.map +1 -1
  30. package/{esm/deps/jsr.io/@std/internal/1.0.13 → script/deps/jsr.io/@std/internal/1.0.14}/diff_str.d.ts.map +1 -1
  31. package/{esm/deps/jsr.io/@std/internal/1.0.13 → script/deps/jsr.io/@std/internal/1.0.14}/format.d.ts.map +1 -1
  32. package/script/deps/jsr.io/@std/internal/{1.0.13 → 1.0.14}/styles.d.ts.map +1 -1
  33. package/script/deps/jsr.io/@std/internal/{1.0.13 → 1.0.14}/types.d.ts.map +1 -1
  34. package/script/mod.d.ts +1 -0
  35. package/script/mod.d.ts.map +1 -1
  36. package/script/mod.js +1 -0
  37. package/script/src/core.d.ts +151 -26
  38. package/script/src/core.d.ts.map +1 -1
  39. package/script/src/core.js +240 -32
  40. package/script/src/dates.d.ts +14 -0
  41. package/script/src/dates.d.ts.map +1 -1
  42. package/script/src/dates.js +20 -0
  43. package/script/src/numbers.d.ts +63 -0
  44. package/script/src/numbers.d.ts.map +1 -1
  45. package/script/src/numbers.js +85 -0
  46. package/script/src/objects.d.ts +90 -0
  47. package/script/src/objects.d.ts.map +1 -0
  48. package/script/src/objects.js +137 -0
  49. package/script/src/objects_test.d.ts.map +1 -0
  50. package/script/src/strings.d.ts +70 -0
  51. package/script/src/strings.d.ts.map +1 -1
  52. package/script/src/strings.js +99 -0
@@ -1 +1 @@
1
- {"version":3,"file":"diff_str.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/internal/1.0.13/diff_str.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAqB,UAAU,EAAE,MAAM,YAAY,CAAC;AAGhE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAY/C;AAKD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,UAAQ,GAAG,MAAM,EAAE,CAiBnE;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,EACxB,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,GAC3B,UAAU,CAAC,MAAM,CAAC,EAAE,CAetB;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,CAkDlE"}
1
+ {"version":3,"file":"diff_str.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/internal/1.0.14/diff_str.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAqB,UAAU,EAAE,MAAM,YAAY,CAAC;AAGhE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAY/C;AAKD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,UAAQ,GAAG,MAAM,EAAE,CAiBnE;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,EACxB,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,GAC3B,UAAU,CAAC,MAAM,CAAC,EAAE,CAetB;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,CAkDlE"}
@@ -1 +1 @@
1
- {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/internal/1.0.13/format.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,SAAS,GAAG,CACtB,CAAC,EAAE,OAAO,EACV,OAAO,EAAE;IACP,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,KACE,MAAM,CAAC;AAEZ;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAmBzC"}
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/internal/1.0.14/format.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,SAAS,GAAG,CACtB,CAAC,EAAE,OAAO,EACV,OAAO,EAAE;IACP,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,KACE,MAAM,CAAC;AAEZ;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAmBzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/internal/1.0.13/styles.ts"],"names":[],"mappings":"AAqCA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAExC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,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CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAExC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAWD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpD"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/internal/1.0.13/types.ts"],"names":[],"mappings":"AAGA,kDAAkD;AAClD,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,iBAAiB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAEvE;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;IAChC,IAAI,EAAE,QAAQ,GAAG,YAAY,CAAC;IAC9B,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC;IAC1B,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;CAC3B,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/internal/1.0.14/types.ts"],"names":[],"mappings":"AAGA,kDAAkD;AAClD,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,iBAAiB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAEvE;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;IAChC,IAAI,EAAE,QAAQ,GAAG,YAAY,CAAC;IAC9B,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC;IAC1B,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;CAC3B,CAAC"}
package/script/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
@@ -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/script/mod.js CHANGED
@@ -18,5 +18,6 @@ __exportStar(require("./src/core.js"), exports);
18
18
  __exportStar(require("./src/dates.js"), exports);
19
19
  __exportStar(require("./src/duration.js"), exports);
20
20
  __exportStar(require("./src/numbers.js"), exports);
21
+ __exportStar(require("./src/objects.js"), exports);
21
22
  __exportStar(require("./src/strings.js"), exports);
22
23
  __exportStar(require("./src/utility_types.js"), exports);
@@ -163,6 +163,10 @@ export declare function reverse<T>(thing: Set<T>): Set<T>;
163
163
  * ```
164
164
  */
165
165
  export declare function isEmpty(thing: unknown): boolean;
166
+ /**
167
+ * Alias for `isEmpty`.
168
+ */
169
+ export declare function isNoneOrEmpty(thing: unknown): boolean;
166
170
  /**
167
171
  * Determines if the given thing is not empty.
168
172
  *
@@ -180,6 +184,10 @@ export declare function isEmpty(thing: unknown): boolean;
180
184
  * ```
181
185
  */
182
186
  export declare function isNotEmpty(thing: unknown): boolean;
187
+ /**
188
+ * Alias for `isNotEmpty`.
189
+ */
190
+ export declare function isNotNoneOrEmpty(thing: unknown): boolean;
183
191
  /**
184
192
  * Returns the distinct values from a list.
185
193
  *
@@ -220,18 +228,6 @@ export declare function distinct<T>(list: T[]): T[];
220
228
  * ```
221
229
  */
222
230
  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
231
  /**
236
232
  * Determines if the given value is truthy.
237
233
  *
@@ -265,7 +261,7 @@ export declare function falsy(thing: unknown): boolean;
265
261
  * isSome({}); // true
266
262
  * ```
267
263
  */
268
- export declare function isSome(thing: unknown): boolean;
264
+ export declare function isSome<T>(thing: T | null | undefined): thing is T;
269
265
  /**
270
266
  * Returns true if the given value is null or undefined.
271
267
  *
@@ -277,7 +273,23 @@ export declare function isSome(thing: unknown): boolean;
277
273
  * isNone(0); // false
278
274
  * ```
279
275
  */
280
- export declare function isNone(thing: unknown): boolean;
276
+ export declare function isNone(thing: unknown): thing is null | undefined;
277
+ /**
278
+ * Determines if the given value is an array. Acts as a type guard, narrowing
279
+ * the value to `unknown[]` in branches where the result is `true`.
280
+ *
281
+ * @remarks alias for `Array.isArray`.
282
+ *
283
+ * @example
284
+ * ```ts
285
+ * isArray([]); // true
286
+ * isArray([1, 2, 3]); // true
287
+ * isArray("hello"); // false
288
+ * isArray(null); // false
289
+ * isArray({}); // false
290
+ * ```
291
+ */
292
+ export declare function isArray(thing: unknown): thing is unknown[];
281
293
  /**
282
294
  * Returns a function that does nothing.
283
295
  *
@@ -301,18 +313,6 @@ export declare function noop(): void;
301
313
  * ```
302
314
  */
303
315
  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
316
  /**
317
317
  * Splits an array into chunks of a fixed size.
318
318
  *
@@ -409,4 +409,129 @@ export declare function includes(searchIn: string | string[] | null | undefined,
409
409
  * ```
410
410
  */
411
411
  export declare function includesAny(searchIn: string | string[] | null | undefined, searchFor: string | string[] | null | undefined): boolean;
412
+ /**
413
+ * Returns a new array with elements removed and/or inserted, without mutating the original.
414
+ *
415
+ * @param list - The source array
416
+ * @param start - Index at which to start changing the array
417
+ * @param deleteCount - Number of elements to remove
418
+ * @param items - Elements to insert at the start index
419
+ * @returns A new array with the modifications applied
420
+ *
421
+ * @example
422
+ * ```ts
423
+ * splice([1, 2, 3, 4], 1, 2) // [1, 4]
424
+ * splice([1, 2, 3], 1, 0, [9, 10]) // [1, 9, 10, 2, 3]
425
+ * splice([1, 2, 3, 4], 2) // [1, 2] — omitting deleteCount removes from start to end
426
+ * ```
427
+ */
428
+ export declare function splice<T>(list: T[], start: number, deleteCount?: number, items?: T[]): T[];
429
+ /**
430
+ * Groups items into a `Map` keyed by the value returned from `keyFn`.
431
+ *
432
+ * @example
433
+ * ```ts
434
+ * groupBy([1, 2, 3, 4], (n) => n % 2 === 0 ? "even" : "odd");
435
+ * // Map { "odd" => [1, 3], "even" => [2, 4] }
436
+ *
437
+ * const people = [{ role: "admin", name: "A" }, { role: "user", name: "B" }];
438
+ * groupBy(people, (p) => p.role);
439
+ * // Map { "admin" => [{...}], "user" => [{...}] }
440
+ * ```
441
+ */
442
+ export declare function groupBy<T, K>(list: T[], keyFn: (item: T) => K): Map<K, T[]>;
443
+ /**
444
+ * Splits a list into two: the first contains items where the predicate is true,
445
+ * the second contains items where it is false.
446
+ *
447
+ * @example
448
+ * ```ts
449
+ * partition([1, 2, 3, 4], (n) => n % 2 === 0); // [[2, 4], [1, 3]]
450
+ * ```
451
+ */
452
+ export declare function partition<T>(list: T[], predicate: (item: T) => boolean): [T[], T[]];
453
+ /**
454
+ * Returns a new array sorted by the value returned from `keyFn`.
455
+ *
456
+ * @remarks
457
+ * Does not mutate the input list.
458
+ *
459
+ * @example
460
+ * ```ts
461
+ * sortBy([{ age: 30 }, { age: 20 }], (p) => p.age); // [{ age: 20 }, { age: 30 }]
462
+ * sortBy(["banana", "apple", "cherry"], (s) => s); // ["apple", "banana", "cherry"]
463
+ * ```
464
+ */
465
+ export declare function sortBy<T>(list: T[], keyFn: (item: T) => number | string): T[];
466
+ /**
467
+ * Removes `null` and `undefined` values from a list.
468
+ *
469
+ * @example
470
+ * ```ts
471
+ * compact([1, null, 2, undefined, 3]); // [1, 2, 3]
472
+ * compact(["a", "", null, "b"]); // ["a", "", "b"]
473
+ * ```
474
+ */
475
+ export declare function compact<T>(list: (T | null | undefined)[]): T[];
476
+ /**
477
+ * Generates a list of numbers in the given range. The start is inclusive,
478
+ * the end is exclusive.
479
+ *
480
+ * @example
481
+ * ```ts
482
+ * range(0, 5); // [0, 1, 2, 3, 4]
483
+ * range(2, 8, 2); // [2, 4, 6]
484
+ * range(5, 0, -1); // [5, 4, 3, 2, 1]
485
+ * ```
486
+ */
487
+ export declare function range(start: number, end: number, step?: number): number[];
488
+ /**
489
+ * Pairs up elements from two lists. Stops at the shorter list.
490
+ *
491
+ * @example
492
+ * ```ts
493
+ * zip([1, 2, 3], ["a", "b", "c"]); // [[1, "a"], [2, "b"], [3, "c"]]
494
+ * zip([1, 2, 3], ["a"]); // [[1, "a"]]
495
+ * ```
496
+ */
497
+ export declare function zip<A, B>(a: A[], b: B[]): [A, B][];
498
+ /**
499
+ * Returns the first `n` elements of a list. Does not mutate the input.
500
+ *
501
+ * @example
502
+ * ```ts
503
+ * take([1, 2, 3, 4], 2); // [1, 2]
504
+ * take([1, 2], 5); // [1, 2]
505
+ * take([1, 2, 3], 0); // []
506
+ * ```
507
+ */
508
+ export declare function take<T>(list: T[], n: number): T[];
509
+ /**
510
+ * Returns a list with the first `n` elements removed. Does not mutate the input.
511
+ *
512
+ * @example
513
+ * ```ts
514
+ * drop([1, 2, 3, 4], 2); // [3, 4]
515
+ * drop([1, 2], 5); // []
516
+ * ```
517
+ */
518
+ export declare function drop<T>(list: T[], n: number): T[];
519
+ /**
520
+ * Returns a new list with the elements at indices `i` and `j` swapped.
521
+ *
522
+ * @example
523
+ * ```ts
524
+ * swap([1, 2, 3, 4], 0, 3); // [4, 2, 3, 1]
525
+ * ```
526
+ */
527
+ export declare function swap<T>(list: T[], i: number, j: number): T[];
528
+ /**
529
+ * Returns a new list with an element moved from one index to another.
530
+ *
531
+ * @example
532
+ * ```ts
533
+ * move([1, 2, 3, 4], 0, 2); // [2, 3, 1, 4]
534
+ * ```
535
+ */
536
+ export declare function move<T>(list: T[], from: number, to: number): T[];
412
537
  //# sourceMappingURL=core.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/src/core.ts"],"names":[],"mappings":"AAEA;;GAEG;AAC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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"}
@@ -11,24 +11,36 @@ exports.stringify = stringify;
11
11
  exports.parse = parse;
12
12
  exports.reverse = reverse;
13
13
  exports.isEmpty = isEmpty;
14
+ exports.isNoneOrEmpty = isNoneOrEmpty;
14
15
  exports.isNotEmpty = isNotEmpty;
16
+ exports.isNotNoneOrEmpty = isNotNoneOrEmpty;
15
17
  exports.unique = unique;
16
18
  exports.distinct = distinct;
17
19
  exports.sample = sample;
18
- exports.random = random;
19
20
  exports.truthy = truthy;
20
21
  exports.falsy = falsy;
21
22
  exports.isSome = isSome;
22
23
  exports.isNone = isNone;
24
+ exports.isArray = isArray;
23
25
  exports.noop = noop;
24
26
  exports.todo = todo;
25
- exports.inRange = inRange;
26
27
  exports.chunk = chunk;
27
28
  exports.union = union;
28
29
  exports.difference = difference;
29
30
  exports.intersection = intersection;
30
31
  exports.includes = includes;
31
32
  exports.includesAny = includesAny;
33
+ exports.splice = splice;
34
+ exports.groupBy = groupBy;
35
+ exports.partition = partition;
36
+ exports.sortBy = sortBy;
37
+ exports.compact = compact;
38
+ exports.range = range;
39
+ exports.zip = zip;
40
+ exports.take = take;
41
+ exports.drop = drop;
42
+ exports.swap = swap;
43
+ exports.move = move;
32
44
  const strings_js_1 = require("./strings.js");
33
45
  /**
34
46
  * Clone an object using structuredClone.
@@ -157,7 +169,7 @@ function reverse(thing) {
157
169
  return thing.split("").reverse().join("");
158
170
  if (thing instanceof Set)
159
171
  return new Set([...thing].reverse());
160
- return thing.reverse();
172
+ return [...thing].reverse();
161
173
  }
162
174
  /**
163
175
  * Determines if the given thing is empty.
@@ -191,6 +203,12 @@ function isEmpty(thing) {
191
203
  return Object.keys(thing).length === 0;
192
204
  return false;
193
205
  }
206
+ /**
207
+ * Alias for `isEmpty`.
208
+ */
209
+ function isNoneOrEmpty(thing) {
210
+ return isEmpty(thing);
211
+ }
194
212
  /**
195
213
  * Determines if the given thing is not empty.
196
214
  *
@@ -210,6 +228,12 @@ function isEmpty(thing) {
210
228
  function isNotEmpty(thing) {
211
229
  return !isEmpty(thing);
212
230
  }
231
+ /**
232
+ * Alias for `isNotEmpty`.
233
+ */
234
+ function isNotNoneOrEmpty(thing) {
235
+ return isNotEmpty(thing);
236
+ }
213
237
  /**
214
238
  * Returns the distinct values from a list.
215
239
  *
@@ -254,21 +278,7 @@ function distinct(list) {
254
278
  * ```
255
279
  */
256
280
  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;
281
+ return list[Math.floor(Math.random() * list.length)];
272
282
  }
273
283
  /**
274
284
  * Determines if the given value is truthy.
@@ -324,6 +334,24 @@ function isSome(thing) {
324
334
  function isNone(thing) {
325
335
  return thing === null || thing === undefined;
326
336
  }
337
+ /**
338
+ * Determines if the given value is an array. Acts as a type guard, narrowing
339
+ * the value to `unknown[]` in branches where the result is `true`.
340
+ *
341
+ * @remarks alias for `Array.isArray`.
342
+ *
343
+ * @example
344
+ * ```ts
345
+ * isArray([]); // true
346
+ * isArray([1, 2, 3]); // true
347
+ * isArray("hello"); // false
348
+ * isArray(null); // false
349
+ * isArray({}); // false
350
+ * ```
351
+ */
352
+ function isArray(thing) {
353
+ return Array.isArray(thing);
354
+ }
327
355
  /**
328
356
  * Returns a function that does nothing.
329
357
  *
@@ -352,20 +380,6 @@ function noop() {
352
380
  function todo(message) {
353
381
  noop();
354
382
  }
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
383
  /**
370
384
  * Splits an array into chunks of a fixed size.
371
385
  *
@@ -497,3 +511,197 @@ function includesAny(searchIn, searchFor) {
497
511
  const terms = Array.isArray(searchFor) ? searchFor : [searchFor];
498
512
  return terms.some((term) => searchIn.includes(term));
499
513
  }
514
+ /**
515
+ * Returns a new array with elements removed and/or inserted, without mutating the original.
516
+ *
517
+ * @param list - The source array
518
+ * @param start - Index at which to start changing the array
519
+ * @param deleteCount - Number of elements to remove
520
+ * @param items - Elements to insert at the start index
521
+ * @returns A new array with the modifications applied
522
+ *
523
+ * @example
524
+ * ```ts
525
+ * splice([1, 2, 3, 4], 1, 2) // [1, 4]
526
+ * splice([1, 2, 3], 1, 0, [9, 10]) // [1, 9, 10, 2, 3]
527
+ * splice([1, 2, 3, 4], 2) // [1, 2] — omitting deleteCount removes from start to end
528
+ * ```
529
+ */
530
+ function splice(list, start, deleteCount, items = []) {
531
+ const copy = [...list];
532
+ copy.splice(start, deleteCount ?? list.length, ...items);
533
+ return copy;
534
+ }
535
+ /**
536
+ * Groups items into a `Map` keyed by the value returned from `keyFn`.
537
+ *
538
+ * @example
539
+ * ```ts
540
+ * groupBy([1, 2, 3, 4], (n) => n % 2 === 0 ? "even" : "odd");
541
+ * // Map { "odd" => [1, 3], "even" => [2, 4] }
542
+ *
543
+ * const people = [{ role: "admin", name: "A" }, { role: "user", name: "B" }];
544
+ * groupBy(people, (p) => p.role);
545
+ * // Map { "admin" => [{...}], "user" => [{...}] }
546
+ * ```
547
+ */
548
+ function groupBy(list, keyFn) {
549
+ const result = new Map();
550
+ for (const item of list) {
551
+ const key = keyFn(item);
552
+ const existing = result.get(key);
553
+ if (existing)
554
+ existing.push(item);
555
+ else
556
+ result.set(key, [item]);
557
+ }
558
+ return result;
559
+ }
560
+ /**
561
+ * Splits a list into two: the first contains items where the predicate is true,
562
+ * the second contains items where it is false.
563
+ *
564
+ * @example
565
+ * ```ts
566
+ * partition([1, 2, 3, 4], (n) => n % 2 === 0); // [[2, 4], [1, 3]]
567
+ * ```
568
+ */
569
+ function partition(list, predicate) {
570
+ const pass = [];
571
+ const fail = [];
572
+ for (const item of list) {
573
+ if (predicate(item))
574
+ pass.push(item);
575
+ else
576
+ fail.push(item);
577
+ }
578
+ return [pass, fail];
579
+ }
580
+ /**
581
+ * Returns a new array sorted by the value returned from `keyFn`.
582
+ *
583
+ * @remarks
584
+ * Does not mutate the input list.
585
+ *
586
+ * @example
587
+ * ```ts
588
+ * sortBy([{ age: 30 }, { age: 20 }], (p) => p.age); // [{ age: 20 }, { age: 30 }]
589
+ * sortBy(["banana", "apple", "cherry"], (s) => s); // ["apple", "banana", "cherry"]
590
+ * ```
591
+ */
592
+ function sortBy(list, keyFn) {
593
+ return [...list].sort((a, b) => {
594
+ const aKey = keyFn(a);
595
+ const bKey = keyFn(b);
596
+ if (aKey < bKey)
597
+ return -1;
598
+ if (aKey > bKey)
599
+ return 1;
600
+ return 0;
601
+ });
602
+ }
603
+ /**
604
+ * Removes `null` and `undefined` values from a list.
605
+ *
606
+ * @example
607
+ * ```ts
608
+ * compact([1, null, 2, undefined, 3]); // [1, 2, 3]
609
+ * compact(["a", "", null, "b"]); // ["a", "", "b"]
610
+ * ```
611
+ */
612
+ function compact(list) {
613
+ return list.filter(isSome);
614
+ }
615
+ /**
616
+ * Generates a list of numbers in the given range. The start is inclusive,
617
+ * the end is exclusive.
618
+ *
619
+ * @example
620
+ * ```ts
621
+ * range(0, 5); // [0, 1, 2, 3, 4]
622
+ * range(2, 8, 2); // [2, 4, 6]
623
+ * range(5, 0, -1); // [5, 4, 3, 2, 1]
624
+ * ```
625
+ */
626
+ function range(start, end, step = 1) {
627
+ if (step === 0)
628
+ throw new Error("range step must not be 0");
629
+ const result = [];
630
+ if (step > 0) {
631
+ for (let i = start; i < end; i += step)
632
+ result.push(i);
633
+ }
634
+ else {
635
+ for (let i = start; i > end; i += step)
636
+ result.push(i);
637
+ }
638
+ return result;
639
+ }
640
+ /**
641
+ * Pairs up elements from two lists. Stops at the shorter list.
642
+ *
643
+ * @example
644
+ * ```ts
645
+ * zip([1, 2, 3], ["a", "b", "c"]); // [[1, "a"], [2, "b"], [3, "c"]]
646
+ * zip([1, 2, 3], ["a"]); // [[1, "a"]]
647
+ * ```
648
+ */
649
+ function zip(a, b) {
650
+ const length = Math.min(a.length, b.length);
651
+ const result = [];
652
+ for (let i = 0; i < length; i++)
653
+ result.push([a[i], b[i]]);
654
+ return result;
655
+ }
656
+ /**
657
+ * Returns the first `n` elements of a list. Does not mutate the input.
658
+ *
659
+ * @example
660
+ * ```ts
661
+ * take([1, 2, 3, 4], 2); // [1, 2]
662
+ * take([1, 2], 5); // [1, 2]
663
+ * take([1, 2, 3], 0); // []
664
+ * ```
665
+ */
666
+ function take(list, n) {
667
+ return list.slice(0, Math.max(0, n));
668
+ }
669
+ /**
670
+ * Returns a list with the first `n` elements removed. Does not mutate the input.
671
+ *
672
+ * @example
673
+ * ```ts
674
+ * drop([1, 2, 3, 4], 2); // [3, 4]
675
+ * drop([1, 2], 5); // []
676
+ * ```
677
+ */
678
+ function drop(list, n) {
679
+ return list.slice(Math.max(0, n));
680
+ }
681
+ /**
682
+ * Returns a new list with the elements at indices `i` and `j` swapped.
683
+ *
684
+ * @example
685
+ * ```ts
686
+ * swap([1, 2, 3, 4], 0, 3); // [4, 2, 3, 1]
687
+ * ```
688
+ */
689
+ function swap(list, i, j) {
690
+ const copy = [...list];
691
+ [copy[i], copy[j]] = [copy[j], copy[i]];
692
+ return copy;
693
+ }
694
+ /**
695
+ * Returns a new list with an element moved from one index to another.
696
+ *
697
+ * @example
698
+ * ```ts
699
+ * move([1, 2, 3, 4], 0, 2); // [2, 3, 1, 4]
700
+ * ```
701
+ */
702
+ function move(list, from, to) {
703
+ const copy = [...list];
704
+ const [item] = copy.splice(from, 1);
705
+ copy.splice(to, 0, item);
706
+ return copy;
707
+ }
@@ -118,4 +118,18 @@ export declare function isInFuture(date: Date): boolean;
118
118
  * Determines if the date is today.
119
119
  */
120
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;
121
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,YAAY,IAAI,MAAM,CAErC;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAItD;AAED;;GAEG;AACH,wBAAgB,YAAY,CA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