@oscarpalmer/atoms 0.185.0 → 0.186.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 (94) hide show
  1. package/dist/array/difference.d.mts +29 -0
  2. package/dist/array/exists.d.mts +35 -0
  3. package/dist/array/filter.d.mts +72 -2
  4. package/dist/array/find.d.mts +70 -0
  5. package/dist/array/first.d.mts +77 -2
  6. package/dist/array/flatten.d.mts +6 -0
  7. package/dist/array/flatten.mjs +6 -0
  8. package/dist/array/from.d.mts +36 -0
  9. package/dist/array/get.d.mts +21 -13
  10. package/dist/array/group-by.d.mts +142 -0
  11. package/dist/array/insert.d.mts +16 -0
  12. package/dist/array/intersection.d.mts +29 -0
  13. package/dist/array/last.d.mts +75 -2
  14. package/dist/array/match.d.mts +161 -32
  15. package/dist/array/move.d.mts +78 -8
  16. package/dist/array/move.mjs +10 -0
  17. package/dist/array/partition.d.mts +35 -0
  18. package/dist/array/push.d.mts +8 -0
  19. package/dist/array/push.mjs +8 -0
  20. package/dist/array/reverse.d.mts +1 -0
  21. package/dist/array/reverse.mjs +1 -0
  22. package/dist/array/select.d.mts +94 -8
  23. package/dist/array/single.d.mts +29 -0
  24. package/dist/array/slice.d.mts +106 -16
  25. package/dist/array/sort.d.mts +21 -0
  26. package/dist/array/splice.d.mts +48 -0
  27. package/dist/array/splice.mjs +2 -1
  28. package/dist/array/swap.d.mts +113 -8
  29. package/dist/array/swap.mjs +1 -0
  30. package/dist/array/to-map.d.mts +124 -0
  31. package/dist/array/to-record.d.mts +124 -0
  32. package/dist/array/to-set.d.mts +24 -0
  33. package/dist/array/toggle.d.mts +38 -3
  34. package/dist/array/union.d.mts +29 -0
  35. package/dist/array/unique.d.mts +24 -0
  36. package/dist/array/update.d.mts +38 -3
  37. package/dist/index.d.mts +1892 -135
  38. package/dist/index.mjs +64 -18
  39. package/dist/internal/array/chunk.d.mts +6 -0
  40. package/dist/internal/array/chunk.mjs +6 -0
  41. package/dist/internal/array/compact.d.mts +12 -0
  42. package/dist/internal/array/index-of.d.mts +70 -0
  43. package/dist/internal/math/aggregate.d.mts +29 -0
  44. package/dist/internal/value/get.d.mts +25 -3
  45. package/dist/internal/value/has.d.mts +4 -4
  46. package/dist/models.d.mts +14 -1
  47. package/dist/value/collection.d.mts +1 -1
  48. package/dist/value/merge.d.mts +28 -25
  49. package/dist/value/merge.mjs +29 -18
  50. package/dist/value/transform.d.mts +1 -1
  51. package/dist/value/unsmush.d.mts +1 -5
  52. package/package.json +5 -5
  53. package/src/array/difference.ts +29 -0
  54. package/src/array/exists.ts +35 -0
  55. package/src/array/filter.ts +72 -2
  56. package/src/array/find.ts +70 -0
  57. package/src/array/first.ts +77 -3
  58. package/src/array/flatten.ts +6 -0
  59. package/src/array/from.ts +36 -0
  60. package/src/array/get.ts +21 -15
  61. package/src/array/group-by.ts +142 -0
  62. package/src/array/insert.ts +16 -2
  63. package/src/array/intersection.ts +29 -0
  64. package/src/array/last.ts +75 -2
  65. package/src/array/match.ts +171 -42
  66. package/src/array/move.ts +82 -12
  67. package/src/array/partition.ts +35 -0
  68. package/src/array/push.ts +8 -2
  69. package/src/array/reverse.ts +1 -0
  70. package/src/array/select.ts +94 -13
  71. package/src/array/single.ts +29 -0
  72. package/src/array/slice.ts +114 -24
  73. package/src/array/sort.ts +21 -0
  74. package/src/array/splice.ts +52 -4
  75. package/src/array/swap.ts +117 -12
  76. package/src/array/to-map.ts +124 -0
  77. package/src/array/to-record.ts +124 -0
  78. package/src/array/to-set.ts +24 -0
  79. package/src/array/toggle.ts +38 -3
  80. package/src/array/union.ts +29 -0
  81. package/src/array/unique.ts +24 -0
  82. package/src/array/update.ts +38 -3
  83. package/src/internal/array/chunk.ts +6 -0
  84. package/src/internal/array/compact.ts +12 -0
  85. package/src/internal/array/index-of.ts +70 -0
  86. package/src/internal/math/aggregate.ts +29 -0
  87. package/src/internal/string.ts +0 -2
  88. package/src/internal/value/get.ts +25 -3
  89. package/src/internal/value/has.ts +4 -4
  90. package/src/models.ts +18 -0
  91. package/src/value/collection.ts +1 -1
  92. package/src/value/merge.ts +88 -66
  93. package/src/value/transform.ts +1 -1
  94. package/src/value/unsmush.ts +1 -10
@@ -3,22 +3,46 @@ import { PlainObject } from "../models.mjs";
3
3
  //#region src/array/to-set.d.ts
4
4
  /**
5
5
  * Create a Set from an array of items using a callback
6
+ *
6
7
  * @param array Array to convert
7
8
  * @param callback Callback to get an item's value
8
9
  * @returns Set of values
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * toSet(
14
+ * [{id: 1}, {id: 2}, {id: 3}],
15
+ * item => item.id,
16
+ * ); // => Set { 1, 2, 3 }
17
+ * ```
9
18
  */
10
19
  declare function toSet<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback): Set<ReturnType<Callback>>;
11
20
  /**
12
21
  * Create a Set from an array of items using a key
22
+ *
13
23
  * @param array Array to convert
14
24
  * @param key Key to use for value
15
25
  * @returns Set of values
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * toSet(
30
+ * [{id: 1}, {id: 2}, {id: 3}],
31
+ * 'id',
32
+ * ); // => Set { 1, 2, 3 }
33
+ * ```
16
34
  */
17
35
  declare function toSet<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Set<Item[ItemKey]>;
18
36
  /**
19
37
  * Create a Set from an array of items
38
+ *
20
39
  * @param array Array to convert
21
40
  * @returns Set of items
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * toSet([1, 2, 3]); // => Set { 1, 2, 3 }
45
+ * ```
22
46
  */
23
47
  declare function toSet<Item>(array: Item[]): Set<Item>;
24
48
  //#endregion
@@ -2,26 +2,61 @@ import { PlainObject } from "../models.mjs";
2
2
 
3
3
  //#region src/array/toggle.d.ts
4
4
  /**
5
- * Toggle an item in an array: if the item exists, it will be removed; if it doesn't, it will be added
5
+ * Toggle an item in an array
6
+ *
7
+ * If the item exists, it will be removed; if it doesn't, it will be added
8
+ *
6
9
  * @param destination Array to toggle within
7
10
  * @param toggled Toggled items
8
11
  * @param callback Callback to find existing item
9
12
  * @returns Original array
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * toggle(
17
+ * [{id: 1}, {id: 2}, {id: 3}],
18
+ * [{id: 2}, {id: 4}],
19
+ * item => item.id,
20
+ * ); // => [{id: 1}, {id: 3}, {id: 4}]
21
+ * ```
10
22
  */
11
23
  declare function toggle<Item>(destination: Item[], toggled: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
12
24
  /**
13
- * Toggle an item in an array: if the item exists, it will be removed; if it doesn't, it will be added
25
+ * Toggle an item in an array
26
+ *
27
+ * If the item exists, it will be removed; if it doesn't, it will be added
28
+ *
14
29
  * @param destination Array to toggle within
15
30
  * @param toggled Toggled items
16
31
  * @param key Key to find existing item
17
32
  * @returns Original array
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * toggle(
37
+ * [{id: 1}, {id: 2}, {id: 3}],
38
+ * [{id: 2}, {id: 4}],
39
+ * 'id',
40
+ * ); // => [{id: 1}, {id: 3}, {id: 4}]
41
+ * ```
18
42
  */
19
43
  declare function toggle<Item extends PlainObject, ItemKey extends keyof Item>(destination: Item[], toggled: Item[], key: ItemKey): Item[];
20
44
  /**
21
- * Toggle an item in an array: if the item exists, it will be removed; if it doesn't, it will be added
45
+ * Toggle an item in an array
46
+ *
47
+ * If the item exists, it will be removed; if it doesn't, it will be added
48
+ *
22
49
  * @param destination Array to toggle within
23
50
  * @param toggled Toggled items
24
51
  * @returns Original array
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * toggle(
56
+ * [1, 2, 3],
57
+ * [2, 4],
58
+ * ); // => [1, 3, 4]
59
+ * ```
25
60
  */
26
61
  declare function toggle<Item>(destination: Item[], toggled: Item[]): Item[];
27
62
  //#endregion
@@ -1,25 +1,54 @@
1
1
  //#region src/array/union.d.ts
2
2
  /**
3
3
  * Get the combined, unique values from two arrays
4
+ *
4
5
  * @param first First array
5
6
  * @param second Second array
6
7
  * @param callback Callback to get an item's value for comparison
7
8
  * @returns Combined, unique values from both arrays
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * union(
13
+ * [{id: 1}, {id: 2}, {id: 3}],
14
+ * [{id: 2}, {id: 4}],
15
+ * item => item.id,
16
+ * ); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
17
+ * ```
8
18
  */
9
19
  declare function union<First, Second>(first: First[], second: Second[], callback: (item: First | Second) => unknown): (First | Second)[];
10
20
  /**
11
21
  * Get the combined, unique values from two arrays
22
+ *
12
23
  * @param first First array
13
24
  * @param second Second array
14
25
  * @param key Key to get an item's value for comparison
15
26
  * @returns Combined, unique values from both arrays
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * union(
31
+ * [{id: 1}, {id: 2}, {id: 3}],
32
+ * [{id: 2}, {id: 4}],
33
+ * 'id',
34
+ * ); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
35
+ * ```
16
36
  */
17
37
  declare function union<First extends Record<string, unknown>, Second extends Record<string, unknown>, SharedKey extends keyof First & keyof Second>(first: First[], second: Second[], key: SharedKey): (First | Second)[];
18
38
  /**
19
39
  * Get the combined, unique values from two arrays
40
+ *
20
41
  * @param first First array
21
42
  * @param second Second array
22
43
  * @returns Combined, unique values from both arrays
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * union(
48
+ * [1, 2, 3],
49
+ * [2, 4],
50
+ * ); // => [1, 2, 3, 4]
51
+ * ```
23
52
  */
24
53
  declare function union<First, Second>(first: First[], second: Second[]): (First | Second)[];
25
54
  //#endregion
@@ -3,22 +3,46 @@ import { PlainObject } from "../models.mjs";
3
3
  //#region src/array/unique.d.ts
4
4
  /**
5
5
  * Get an array of unique items
6
+ *
6
7
  * @param array Original array
7
8
  * @param callback Callback to get an item's value
8
9
  * @returns Array of unique items
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * unique(
14
+ * [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
15
+ * item => item.id,
16
+ * ); // => [{id: 1}, {id: 2}, {id: 3}]
17
+ * ```
9
18
  */
10
19
  declare function unique<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
11
20
  /**
12
21
  * Get an array of unique items
22
+ *
13
23
  * @param array Original array
14
24
  * @param key Key to use for unique value
15
25
  * @returns Array of unique items
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * unique(
30
+ * [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
31
+ * 'id',
32
+ * ); // => [{id: 1}, {id: 2}, {id: 3}]
33
+ * ```
16
34
  */
17
35
  declare function unique<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Item[];
18
36
  /**
19
37
  * Get an array of unique items
38
+ *
20
39
  * @param array Original array
21
40
  * @returns Array of unique items
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * unique([1, 2, 3, 2]); // => [1, 2, 3]
45
+ * ```
22
46
  */
23
47
  declare function unique<Item>(array: Item[]): Item[];
24
48
  //#endregion
@@ -2,26 +2,61 @@ import { PlainObject } from "../models.mjs";
2
2
 
3
3
  //#region src/array/update.d.ts
4
4
  /**
5
- * Update an item in an array: if the item exists, it will be updated; if it doesn't, it will be added
5
+ * Update an item in an array
6
+ *
7
+ * If the item exists, it will be updated; if it doesn't, it will be added
8
+ *
6
9
  * @param destination Array to update within
7
10
  * @param updated Updated items
8
11
  * @param callback Callback to find existing item
9
12
  * @returns Original array
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * update(
17
+ * [{id: 1}, {id: 2}, {id: 3}],
18
+ * [{id: 2, name: 'Updated'}, {id: 4, name: 'New'}],
19
+ * item => item.id,
20
+ * ); // => [{id: 1}, {id: 2, name: 'Updated'}, {id: 3}, {id: 4, name: 'New'}]
21
+ * ```
10
22
  */
11
23
  declare function update<Item>(destination: Item[], updated: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
12
24
  /**
13
- * Update an item in an array: if the item exists, it will be updated; if it doesn't, it will be added
25
+ * Update an item in an array
26
+ *
27
+ * If the item exists, it will be updated; if it doesn't, it will be added
28
+ *
14
29
  * @param destination Array to update within
15
30
  * @param updated Updated items
16
31
  * @param key Key to find existing item
17
32
  * @returns Original array
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * update(
37
+ * [{id: 1}, {id: 2}, {id: 3}],
38
+ * [{id: 2, name: 'Updated'}, {id: 4, name: 'New'}],
39
+ * 'id',
40
+ * ); // => [{id: 1}, {id: 2, name: 'Updated'}, {id: 3}, {id: 4, name: 'New'}]
41
+ * ```
18
42
  */
19
43
  declare function update<Item extends PlainObject, ItemKey extends keyof Item>(destination: Item[], updated: Item[], key: ItemKey): Item[];
20
44
  /**
21
- * Update an item in an array: if the item exists, it will be updated; if it doesn't, it will be added
45
+ * Update an item in an array
46
+ *
47
+ * If the item exists, it will be updated; if it doesn't, it will be added
48
+ *
22
49
  * @param destination Array to update within
23
50
  * @param updated Updated items
24
51
  * @returns Original array
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * update(
56
+ * [1, 2, 3],
57
+ * [2, 4],
58
+ * ); // => [1, 2, 3, 4]
59
+ * ```
25
60
  */
26
61
  declare function update<Item>(destination: Item[], updated: Item[]): Item[];
27
62
  //#endregion