@oscarpalmer/atoms 0.184.2 → 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 (156) 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/index.d.mts +2 -2
  12. package/dist/array/index.mjs +2 -2
  13. package/dist/array/insert.d.mts +16 -0
  14. package/dist/array/intersection.d.mts +29 -0
  15. package/dist/array/last.d.mts +75 -2
  16. package/dist/array/{position.d.mts → match.d.mts} +168 -36
  17. package/dist/array/{position.mjs → match.mjs} +16 -16
  18. package/dist/array/move.d.mts +78 -8
  19. package/dist/array/move.mjs +11 -1
  20. package/dist/array/partition.d.mts +35 -0
  21. package/dist/array/push.d.mts +8 -0
  22. package/dist/array/push.mjs +8 -0
  23. package/dist/array/reverse.d.mts +1 -0
  24. package/dist/array/reverse.mjs +1 -0
  25. package/dist/array/select.d.mts +94 -8
  26. package/dist/array/single.d.mts +29 -0
  27. package/dist/array/slice.d.mts +106 -16
  28. package/dist/array/sort.d.mts +30 -4
  29. package/dist/array/sort.mjs +1 -1
  30. package/dist/array/splice.d.mts +48 -0
  31. package/dist/array/splice.mjs +2 -1
  32. package/dist/array/swap.d.mts +113 -8
  33. package/dist/array/swap.mjs +2 -1
  34. package/dist/array/to-map.d.mts +124 -0
  35. package/dist/array/to-record.d.mts +124 -0
  36. package/dist/array/to-set.d.mts +24 -0
  37. package/dist/array/toggle.d.mts +38 -3
  38. package/dist/array/union.d.mts +29 -0
  39. package/dist/array/unique.d.mts +24 -0
  40. package/dist/array/update.d.mts +38 -3
  41. package/dist/beacon.d.mts +12 -0
  42. package/dist/beacon.mjs +9 -0
  43. package/dist/color/instance.d.mts +8 -0
  44. package/dist/color/instance.mjs +3 -0
  45. package/dist/color/models.d.mts +30 -0
  46. package/dist/function/assert.d.mts +29 -8
  47. package/dist/function/assert.mjs +29 -8
  48. package/dist/function/memoize.d.mts +3 -0
  49. package/dist/function/memoize.mjs +3 -0
  50. package/dist/function/retry.d.mts +3 -0
  51. package/dist/function/retry.mjs +3 -0
  52. package/dist/function/work.mjs +1 -1
  53. package/dist/index.d.mts +2158 -288
  54. package/dist/index.mjs +294 -181
  55. package/dist/internal/array/chunk.d.mts +6 -0
  56. package/dist/internal/array/chunk.mjs +6 -0
  57. package/dist/internal/array/compact.d.mts +12 -0
  58. package/dist/internal/array/index-of.d.mts +70 -0
  59. package/dist/internal/math/aggregate.d.mts +29 -0
  60. package/dist/internal/value/compare.d.mts +2 -1
  61. package/dist/internal/value/equal.d.mts +5 -0
  62. package/dist/internal/value/get.d.mts +27 -5
  63. package/dist/internal/value/has.d.mts +7 -7
  64. package/dist/internal/value/has.mjs +1 -1
  65. package/dist/internal/value/misc.d.mts +2 -2
  66. package/dist/internal/value/misc.mjs +10 -4
  67. package/dist/logger.d.mts +11 -0
  68. package/dist/logger.mjs +11 -0
  69. package/dist/models.d.mts +14 -1
  70. package/dist/promise/helpers.mjs +1 -1
  71. package/dist/promise/index.d.mts +0 -6
  72. package/dist/promise/models.d.mts +36 -0
  73. package/dist/promise/models.mjs +6 -0
  74. package/dist/queue.d.mts +13 -1
  75. package/dist/queue.mjs +9 -0
  76. package/dist/result/index.d.mts +0 -8
  77. package/dist/result/index.mjs +0 -8
  78. package/dist/result/match.d.mts +4 -4
  79. package/dist/result/work/flow.d.mts +12 -36
  80. package/dist/result/work/pipe.d.mts +11 -33
  81. package/dist/sized/set.d.mts +3 -2
  82. package/dist/sized/set.mjs +3 -2
  83. package/dist/value/collection.d.mts +1 -1
  84. package/dist/value/handle.mjs +1 -1
  85. package/dist/value/merge.d.mts +28 -25
  86. package/dist/value/merge.mjs +29 -18
  87. package/dist/value/shake.d.mts +3 -0
  88. package/dist/value/smush.d.mts +3 -0
  89. package/dist/value/transform.d.mts +10 -1
  90. package/dist/value/unsmush.d.mts +2 -3
  91. package/package.json +5 -5
  92. package/src/array/difference.ts +33 -0
  93. package/src/array/exists.ts +35 -0
  94. package/src/array/filter.ts +72 -2
  95. package/src/array/find.ts +70 -0
  96. package/src/array/first.ts +77 -3
  97. package/src/array/flatten.ts +6 -0
  98. package/src/array/from.ts +40 -0
  99. package/src/array/get.ts +21 -15
  100. package/src/array/group-by.ts +142 -0
  101. package/src/array/index.ts +1 -1
  102. package/src/array/insert.ts +16 -2
  103. package/src/array/intersection.ts +33 -0
  104. package/src/array/last.ts +75 -2
  105. package/src/array/{position.ts → match.ts} +197 -65
  106. package/src/array/move.ts +87 -13
  107. package/src/array/partition.ts +35 -0
  108. package/src/array/push.ts +8 -2
  109. package/src/array/reverse.ts +5 -0
  110. package/src/array/select.ts +96 -13
  111. package/src/array/single.ts +29 -0
  112. package/src/array/slice.ts +114 -24
  113. package/src/array/sort.ts +30 -4
  114. package/src/array/splice.ts +52 -4
  115. package/src/array/swap.ts +122 -13
  116. package/src/array/to-map.ts +124 -0
  117. package/src/array/to-record.ts +124 -0
  118. package/src/array/to-set.ts +24 -0
  119. package/src/array/toggle.ts +42 -3
  120. package/src/array/union.ts +33 -0
  121. package/src/array/unique.ts +24 -0
  122. package/src/array/update.ts +38 -3
  123. package/src/beacon.ts +12 -0
  124. package/src/color/index.ts +0 -3
  125. package/src/color/instance.ts +9 -1
  126. package/src/color/models.ts +30 -0
  127. package/src/function/assert.ts +66 -7
  128. package/src/function/memoize.ts +3 -0
  129. package/src/function/once.ts +5 -1
  130. package/src/function/retry.ts +3 -0
  131. package/src/internal/array/chunk.ts +6 -0
  132. package/src/internal/array/compact.ts +12 -0
  133. package/src/internal/array/index-of.ts +70 -0
  134. package/src/internal/math/aggregate.ts +29 -0
  135. package/src/internal/string.ts +0 -2
  136. package/src/internal/value/compare.ts +2 -1
  137. package/src/internal/value/equal.ts +5 -0
  138. package/src/internal/value/get.ts +27 -5
  139. package/src/internal/value/has.ts +10 -10
  140. package/src/internal/value/misc.ts +24 -13
  141. package/src/logger.ts +11 -0
  142. package/src/models.ts +18 -0
  143. package/src/promise/index.ts +0 -6
  144. package/src/promise/models.ts +36 -0
  145. package/src/queue.ts +13 -1
  146. package/src/result/index.ts +0 -8
  147. package/src/result/match.ts +4 -4
  148. package/src/result/work/flow.ts +12 -36
  149. package/src/result/work/pipe.ts +11 -33
  150. package/src/sized/set.ts +4 -3
  151. package/src/value/collection.ts +1 -1
  152. package/src/value/merge.ts +88 -66
  153. package/src/value/shake.ts +3 -0
  154. package/src/value/smush.ts +3 -0
  155. package/src/value/transform.ts +10 -1
  156. package/src/value/unsmush.ts +2 -8
@@ -1,9 +1,15 @@
1
1
  //#region src/internal/array/chunk.d.ts
2
2
  /**
3
3
  * Chunk an array into smaller arrays
4
+ *
4
5
  * @param array Array to chunk
5
6
  * @param size Size of each chunk _(minimum is `1`, maximum is `5000`; defaults to `5000`)_
6
7
  * @returns Array of arrays
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * chunk([1, 2, 3, 4, 5], 2); // => [[1, 2], [3, 4], [5]]
12
+ * ```
7
13
  */
8
14
  declare function chunk<Item>(array: Item[], size?: number): Item[][];
9
15
  //#endregion
@@ -1,9 +1,15 @@
1
1
  //#region src/internal/array/chunk.ts
2
2
  /**
3
3
  * Chunk an array into smaller arrays
4
+ *
4
5
  * @param array Array to chunk
5
6
  * @param size Size of each chunk _(minimum is `1`, maximum is `5000`; defaults to `5000`)_
6
7
  * @returns Array of arrays
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * chunk([1, 2, 3, 4, 5], 2); // => [[1, 2], [3, 4], [5]]
12
+ * ```
7
13
  */
8
14
  function chunk(array, size) {
9
15
  if (!Array.isArray(array)) return [];
@@ -1,15 +1,27 @@
1
1
  //#region src/internal/array/compact.d.ts
2
2
  /**
3
3
  * Compact an array _(removing all false-y values)_
4
+ *
4
5
  * @param array Array to compact
5
6
  * @param strict True to remove all false-y values
6
7
  * @returns Compacted array
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * compact([0, 1, '', 'hello', false, true, null, undefined]); // => [1, 'hello', true]
12
+ * ```
7
13
  */
8
14
  declare function compact<Item>(array: Item[], strict: true): Exclude<Item, 0 | '' | false | null | undefined>[];
9
15
  /**
10
16
  * Compact an array _(removing all `null` and `undefined` values)_
17
+ *
11
18
  * @param array Array to compact
12
19
  * @returns Compacted array
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * compact([0, 1, '', 'hello', false, true, null, undefined]); // => [0, 1, '', 'hello', false, true]
24
+ * ```
13
25
  */
14
26
  declare function compact<Item>(array: Item[]): Exclude<Item, null | undefined>[];
15
27
  //#endregion
@@ -3,32 +3,67 @@ import { PlainObject } from "../../models.mjs";
3
3
  //#region src/internal/array/index-of.d.ts
4
4
  /**
5
5
  * Get the index of the first matching item by callback
6
+ *
6
7
  * @param array Array to search in
7
8
  * @param callback Callback to get an item's value
8
9
  * @param value Value to match against
9
10
  * @returns Index of the first matching item, or `-1` if no match is found
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * indexOf(
15
+ * [{id: 1}, {id: 2}, {id: 3}],
16
+ * item => item.id,
17
+ * 2,
18
+ * ); // => 1
19
+ * ```
10
20
  */
11
21
  declare function indexOf<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): number;
12
22
  /**
13
23
  * Get the index of the first matching item by key
24
+ *
14
25
  * @param array Array to search in
15
26
  * @param key Key to match items by
16
27
  * @param value Value to match against
17
28
  * @returns Index of the first matching item, or `-1` if no match is found
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * indexOf(
33
+ * [{id: 1}, {id: 2}, {id: 3}],
34
+ * 'id',
35
+ * 2,
36
+ * ); // => 1
37
+ * ```
18
38
  */
19
39
  declare function indexOf<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
20
40
  /**
21
41
  * Get the index of the first item matching the filter
42
+ *
22
43
  * @param array Array to search in
23
44
  * @param filter Filter callback to match items
24
45
  * @returns Index of the first matching item, or `-1` if no match is found
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * indexOf(
50
+ * [{id: 1}, {id: 2}, {id: 3}],
51
+ * item => item.id === 2,
52
+ * ); // => 1
53
+ * ```
25
54
  */
26
55
  declare function indexOf<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): number;
27
56
  /**
28
57
  * Get the index of the first item matching the given item
58
+ *
29
59
  * @param array Array to search in
30
60
  * @param item Item to match against
31
61
  * @returns Index of the first matching item, or `-1` if no match is found
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * indexOf([1, 2, 3, 4, 5], 3); // => 2
66
+ * ```
32
67
  */
33
68
  declare function indexOf<Item>(array: Item[], item: Item): number;
34
69
  declare namespace indexOf {
@@ -38,38 +73,73 @@ declare namespace indexOf {
38
73
  * Get the index of the last matching item by callback
39
74
  *
40
75
  * Available as `lastIndexOf` and `indexOf.last`
76
+ *
41
77
  * @param array Array to search in
42
78
  * @param callback Callback to get an item's value
43
79
  * @param value Value to match against
44
80
  * @returns Index of the last matching item, or `-1` if no match is found
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * lastIndexOf(
85
+ * [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
86
+ * item => item.id,
87
+ * 2,
88
+ * ); // => 3
89
+ * ```
45
90
  */
46
91
  declare function lastIndexOf<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): number;
47
92
  /**
48
93
  * Get the index of the last matching item by key
49
94
  *
50
95
  * Available as `lastIndexOf` and `indexOf.last`
96
+ *
51
97
  * @param array Array to search in
52
98
  * @param key Key to match items by
53
99
  * @param value Value to match against
54
100
  * @returns Index of the last matching item, or `-1` if no match is found
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * lastIndexOf(
105
+ * [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
106
+ * 'id',
107
+ * 2,
108
+ * ); // => 3
109
+ * ```
55
110
  */
56
111
  declare function lastIndexOf<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
57
112
  /**
58
113
  * Get the index of the last item matching the filter
59
114
  *
60
115
  * Available as `lastIndexOf` and `indexOf.last`
116
+ *
61
117
  * @param array Array to search in
62
118
  * @param filter Filter callback to match items
63
119
  * @returns Index of the last matching item, or `-1` if no match is found
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * lastIndexOf(
124
+ * [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
125
+ * item => item.id === 2,
126
+ * ); // => 3
127
+ * ```
64
128
  */
65
129
  declare function lastIndexOf<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): number;
66
130
  /**
67
131
  * Get the index of the last item matching the given item
68
132
  *
69
133
  * Available as `lastIndexOf` and `indexOf.last`
134
+ *
70
135
  * @param array Array to search in
71
136
  * @param item Item to match against
72
137
  * @returns Index of the last matching item, or `-1` if no match is found
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * lastIndexOf([1, 2, 3, 2, 1], 2); // => 3
142
+ * ```
73
143
  */
74
144
  declare function lastIndexOf<Item>(array: Item[], item: Item): number;
75
145
  //#endregion
@@ -11,6 +11,17 @@ declare function aggregate(type: AggregationType, array: unknown[], key: unknown
11
11
  declare function getAggregateCallback(key: unknown): Function | undefined;
12
12
  /**
13
13
  * Get the maximum value from a list of items
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * max(
18
+ * [{id: 1, value: 10}, {id: 2, value: 20}],
19
+ * item => item.value,
20
+ * ); // 20
21
+ *
22
+ * max([], item => item.value); // Number.NaN
23
+ * ```
24
+ *
14
25
  * @param items List of items
15
26
  * @param callback Callback to get an item's value
16
27
  * @returns Maximum value, or `NaN` if no maximum can be found
@@ -18,6 +29,17 @@ declare function getAggregateCallback(key: unknown): Function | undefined;
18
29
  declare function max<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
19
30
  /**
20
31
  * Get the maximum value from a list of items
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * max(
36
+ * [{id: 1, value: 10}, {id: 2, value: 20}],
37
+ * 'value',
38
+ * ); // 20
39
+ *
40
+ * max([], 'value'); // Number.NaN
41
+ * ```
42
+ *
21
43
  * @param items List of items
22
44
  * @param key Key to use for value
23
45
  * @returns Maximum value, or `NaN` if no maximum can be found
@@ -25,6 +47,13 @@ declare function max<Item>(items: Item[], callback: (item: Item, index: number,
25
47
  declare function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(items: Item[], key: ItemKey): number;
26
48
  /**
27
49
  * Get the maximum value from a list of numbers
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * max([10, 20]); // 20
54
+ * max([]); // Number.NaN
55
+ * ```
56
+ *
28
57
  * @param values List of numbers
29
58
  * @returns Maximum value, or `NaN` if no maximum can be found
30
59
  */
@@ -1,6 +1,7 @@
1
1
  import { Constructor, GenericCallback } from "../../models.mjs";
2
2
 
3
3
  //#region src/internal/value/compare.d.ts
4
+ type Comparator<Value = any> = (first: Value, second: Value) => number;
4
5
  /**
5
6
  * Compare two values _(for sorting purposes)_
6
7
  * @param first First value
@@ -31,6 +32,6 @@ declare function deregisterComparator<Instance>(constructor: Constructor<Instanc
31
32
  * @param constructor Class constructor
32
33
  * @param handler Method name or comparison function _(defaults to `compare`)_
33
34
  */
34
- declare function registerComparator<Instance>(constructor: Constructor<Instance>, handler?: string | ((first: Instance, second: Instance) => number)): void;
35
+ declare function registerComparator<Instance>(constructor: Constructor<Instance>, handler?: string | Comparator<Instance>): void;
35
36
  //#endregion
36
37
  export { compare, deregisterComparator, registerComparator };
@@ -18,6 +18,11 @@ type EqualOptions = {
18
18
  */
19
19
  relaxedNullish?: boolean;
20
20
  };
21
+ /**
22
+ * An equalizer function for comparing values for equality, with predefined options
23
+ *
24
+ * Can be used to compare values, and register or deregister equality comparison handlers for specific classes
25
+ */
21
26
  type Equalizer = {
22
27
  /**
23
28
  * Are two strings equal?
@@ -1,18 +1,40 @@
1
- import { NestedKeys, NestedValue, PlainObject, ToString } from "../../models.mjs";
1
+ import { NestedKeys, NestedValue, PlainObject } from "../../models.mjs";
2
2
 
3
3
  //#region src/internal/value/get.d.ts
4
4
  /**
5
5
  * Get the value from an object using a known path
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const data = {foo: {bar: {baz: 42}}};
10
+ *
11
+ * getValue(data, 'foo'); // {bar: {baz: 42}}
12
+ * getValue(data, 'foo.bar'); // {baz: 42}
13
+ * getValue(data, 'foo.bar.baz'); // 42
14
+ * getValue(data, 'foo.nope'); // undefined
15
+ * ```
16
+ *
6
17
  * @param data Object to get value from
7
- * @param path Path for value, e.g., `foo.bar.baz`
18
+ * @param path Path for value
8
19
  * @returns Found value, or `undefined`
9
20
  */
10
- declare function getValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): NestedValue<Data, ToString<Path>>;
21
+ declare function getValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): NestedValue<Data, Path>;
11
22
  /**
12
23
  * Get the value from an object using an unknown path
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * const data = {foo: {bar: {baz: 42}}};
28
+ *
29
+ * getValue(data, 'foo'); // {bar: {baz: 42}}
30
+ * getValue(data, 'foo.bar'); // {baz: 42}
31
+ * getValue(data, 'Foo.Bar.Baz', true); // 42
32
+ * getValue(data, 'foo.nope'); // undefined
33
+ * ```
34
+ *
13
35
  * @param data Object to get value from
14
- * @param path Path for value, e.g., `foo.bar.baz`
15
- * @param ignoreCase If `true`, the path matching is case-insensitive
36
+ * @param path Path for value
37
+ * @param ignoreCase If `true`, path matching is case-insensitive
16
38
  * @returns Found value, or `undefined`
17
39
  */
18
40
  declare function getValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): unknown;
@@ -6,7 +6,7 @@ import { Result } from "../../result/models.mjs";
6
6
  * Check if a nested property is defined in an object
7
7
  * @param data Object to check in
8
8
  * @param path Path for property
9
- * @return `true` if the property exists, `false` otherwise
9
+ * @returns `true` if the property exists, `false` otherwise
10
10
  */
11
11
  declare function hasValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): boolean;
12
12
  /**
@@ -14,7 +14,7 @@ declare function hasValue<Data extends PlainObject, Path extends NestedKeys<Data
14
14
  * @param data Object to check in
15
15
  * @param path Path for property
16
16
  * @param ignoreCase If `true`, the path matching is case-insensitive
17
- * @return `true` if the property exists, `false` otherwise
17
+ * @returns `true` if the property exists, `false` otherwise
18
18
  */
19
19
  declare function hasValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): boolean;
20
20
  declare namespace hasValue {
@@ -27,9 +27,9 @@ declare namespace hasValue {
27
27
  * @param data Object to check in
28
28
  * @param path Path for property
29
29
  * @param ignoreCase If `true`, the path matching is case-insensitive
30
- * @return Result object
30
+ * @returns Result object
31
31
  */
32
- declare function hasValueResult<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path, ignoreCase?: boolean): Result<NestedValue<Data, ToString<Path>>, undefined>;
32
+ declare function hasValueResult<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path, ignoreCase?: boolean): Result<NestedValue<Data, ToString<Path>>, string>;
33
33
  /**
34
34
  * Check if a nested property is defined in an object, and get its value if it is
35
35
  *
@@ -37,8 +37,8 @@ declare function hasValueResult<Data extends PlainObject, Path extends NestedKey
37
37
  * @param data Object to check in
38
38
  * @param path Path for property
39
39
  * @param ignoreCase If `true`, the path matching is case-insensitive
40
- * @return Result object
40
+ * @returns Result object
41
41
  */
42
- declare function hasValueResult<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): Result<unknown, undefined>;
42
+ declare function hasValueResult<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): Result<unknown, string>;
43
43
  //#endregion
44
- export { hasValue };
44
+ export { hasValue, hasValueResult };
@@ -8,4 +8,4 @@ function hasValueResult(data, path, ignoreCase) {
8
8
  return getNestedValue(data, path, ignoreCase === true);
9
9
  }
10
10
  //#endregion
11
- export { hasValue };
11
+ export { hasValue, hasValueResult };
@@ -2,9 +2,9 @@ import { Result } from "../../result/models.mjs";
2
2
 
3
3
  //#region src/internal/value/misc.d.ts
4
4
  declare function findKey(needle: string, haystack: object): string;
5
- declare function getNestedValue(data: object, path: string, ignoreCase: boolean): Result<unknown, undefined>;
5
+ declare function getNestedValue(data: object, path: string, ignoreCase: boolean): Result<unknown, string>;
6
6
  declare function getPaths(path: string, lowercase: boolean): string | string[];
7
- declare function handleValue(data: object, path: string, value: unknown, get: true, ignoreCase: boolean): Result<unknown, undefined>;
7
+ declare function handleValue(data: object, path: string, value: unknown, get: true, ignoreCase: boolean): Result<unknown, string>;
8
8
  declare function handleValue(data: object, path: string, value: unknown, get: false, ignoreCase: boolean): void;
9
9
  //#endregion
10
10
  export { findKey, getNestedValue, getPaths, handleValue };
@@ -7,7 +7,8 @@ function findKey(needle, haystack) {
7
7
  return index > -1 ? keys[index] : needle;
8
8
  }
9
9
  function getNestedValue(data, path, ignoreCase) {
10
- if (typeof data !== "object" || data === null || typeof path !== "string" || path.trim().length === 0) return error(void 0);
10
+ if (typeof data !== "object" || data === null) return error(NESTED_MESSAGE_INPUT);
11
+ if (typeof path !== "string" || path.trim().length === 0) return error(NESTED_MESSAGE_PATH);
11
12
  const shouldIgnoreCase = ignoreCase === true;
12
13
  const paths = getPaths(path, shouldIgnoreCase);
13
14
  if (typeof paths === "string") return handleValue(data, paths, null, true, shouldIgnoreCase);
@@ -27,15 +28,20 @@ function getPaths(path, lowercase) {
27
28
  return normalized.replace(EXPRESSION_BRACKET, ".$1").replace(EXPRESSION_DOTS, "").split(".");
28
29
  }
29
30
  function handleValue(data, path, value, get, ignoreCase) {
30
- if (typeof data === "object" && data !== null && !ignoreKey(path)) {
31
+ if (typeof data === "object" && data !== null) {
32
+ if (ignoreKey(path)) return error(NESTED_MESSAGE_UNSAFE);
31
33
  const key = ignoreCase ? findKey(path, data) : path;
32
- if (get) return key in data ? ok(data[key]) : error(void 0);
34
+ if (get) return key in data ? ok(data[key]) : error(NESTED_MESSAGE_MISSING);
33
35
  data[key] = typeof value === "function" ? value(data[key]) : value;
34
36
  }
35
- if (get) return error(void 0);
37
+ if (get) return error(NESTED_MESSAGE_MISSING);
36
38
  }
37
39
  const EXPRESSION_BRACKET = /\[(\w+)\]/g;
38
40
  const EXPRESSION_DOTS = /^\.|\.$/g;
39
41
  const EXPRESSION_NESTED = /\.|\[\w+\]/;
42
+ const NESTED_MESSAGE_INPUT = "Expected data to be an object";
43
+ const NESTED_MESSAGE_MISSING = "Expected property to exist in object";
44
+ const NESTED_MESSAGE_PATH = "Expected path to be a string";
45
+ const NESTED_MESSAGE_UNSAFE = "Access to this property is not allowed";
40
46
  //#endregion
41
47
  export { findKey, getNestedValue, getPaths, handleValue };
package/dist/logger.d.mts CHANGED
@@ -1,4 +1,9 @@
1
1
  //#region src/logger.d.ts
2
+ /**
3
+ * A logger that can be used to log messages to the console
4
+ *
5
+ * _(Logging can be enabled or disabled by setting the `enabled` property)_
6
+ */
2
7
  declare class Logger {
3
8
  /**
4
9
  * Log any number of values at the "debug" log level
@@ -47,8 +52,14 @@ declare class Logger {
47
52
  */
48
53
  time(label: string): Time;
49
54
  }
55
+ /**
56
+ * A named timer that can be used to log durations to the console
57
+ */
50
58
  declare class Time {
51
59
  #private;
60
+ /**
61
+ * Is the timer active? _(i.e. has it been started and not stopped, and is logging enabled?)_
62
+ */
52
63
  get active(): boolean;
53
64
  /**
54
65
  * Log the current duration of the timer _(ignored if logging is disabled)_
package/dist/logger.mjs CHANGED
@@ -1,5 +1,10 @@
1
1
  import { noop } from "./internal/function/misc.mjs";
2
2
  //#region src/logger.ts
3
+ /**
4
+ * A logger that can be used to log messages to the console
5
+ *
6
+ * _(Logging can be enabled or disabled by setting the `enabled` property)_
7
+ */
3
8
  var Logger = class {
4
9
  /**
5
10
  * Log any number of values at the "debug" log level
@@ -70,10 +75,16 @@ var Logger = class {
70
75
  return new Time(label);
71
76
  }
72
77
  };
78
+ /**
79
+ * A named timer that can be used to log durations to the console
80
+ */
73
81
  var Time = class {
74
82
  #logger;
75
83
  #stopper;
76
84
  #state;
85
+ /**
86
+ * Is the timer active? _(i.e. has it been started and not stopped, and is logging enabled?)_
87
+ */
77
88
  get active() {
78
89
  return this.#state.started && !this.#state.stopped && enabled;
79
90
  }
package/dist/models.d.mts CHANGED
@@ -143,5 +143,18 @@ type ToString<Value> = Value extends string | number ? `${Value}` : never;
143
143
  * A union type of all typed arrays
144
144
  */
145
145
  type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
146
+ /**
147
+ * Converts a union type to an intersection type
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * type A = {a: string};
152
+ * type B = {b: number};
153
+ * type C = UnionToIntersection<A | B>; // {a: string} & {b: number}
154
+ * ```
155
+ *
156
+ * Thanks, type-fest!
157
+ */
158
+ type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
146
159
  //#endregion
147
- export { ArrayOrPlainObject, AsyncCancelableCallback, BuiltIns, CancelableCallback, Constructor, EventPosition, GenericAsyncCallback, GenericCallback, Key, KeyedValue, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NumericalKeys, NumericalValues, OnceAsyncCallback, OnceCallback, PlainObject, Primitive, RequiredKeys, Simplify, ToString, TypedArray };
160
+ export { ArrayOrPlainObject, AsyncCancelableCallback, BuiltIns, CancelableCallback, Constructor, EventPosition, GenericAsyncCallback, GenericCallback, Key, KeyedValue, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NumericalKeys, NumericalValues, OnceAsyncCallback, OnceCallback, PlainObject, Primitive, RequiredKeys, Simplify, ToString, TypedArray, UnionToIntersection };
@@ -1,5 +1,5 @@
1
- import { getNumberOrDefault } from "../internal/number.mjs";
2
1
  import { error, ok } from "../result/misc.mjs";
2
+ import { getNumberOrDefault } from "../internal/number.mjs";
3
3
  import { PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "./models.mjs";
4
4
  //#region src/promise/helpers.ts
5
5
  function getPromiseOptions(input) {
@@ -4,8 +4,6 @@ import { PromiseOptions, PromisesItems, PromisesOptions, PromisesResult, Promise
4
4
  //#region src/promise/index.d.ts
5
5
  /**
6
6
  * Wrap a promise with safety handlers, with optional abort capabilities and timeout
7
- *
8
- * Available as `attemptPromise` and `attempt.promise`
9
7
  * @param promise Promise to wrap
10
8
  * @param options Options for the promise
11
9
  * @returns Wrapped promise
@@ -13,8 +11,6 @@ import { PromiseOptions, PromisesItems, PromisesOptions, PromisesResult, Promise
13
11
  declare function attemptPromise<Value>(promise: Promise<Value>, options?: PromiseOptions | AbortSignal | number): Promise<Value>;
14
12
  /**
15
13
  * Wrap a promise-returning callback with safety handlers, with optional abort capabilities and timeout
16
- *
17
- * Available as `attemptPromise` and `attempt.promise`
18
14
  * @param callback Callback to wrap
19
15
  * @param options Options for the promise
20
16
  * @returns Promise-wrapped callback
@@ -22,8 +18,6 @@ declare function attemptPromise<Value>(promise: Promise<Value>, options?: Promis
22
18
  declare function attemptPromise<Value>(callback: () => Promise<Value>, options?: PromiseOptions | AbortSignal | number): Promise<Value>;
23
19
  /**
24
20
  * Wrap a callback with a promise and safety handlers, with optional abort capabilities and timeout
25
- *
26
- * Available as `attemptPromise` and `attempt.promise`
27
21
  * @param callback Callback to wrap
28
22
  * @param options Options for the promise
29
23
  * @returns Promise-wrapped callback
@@ -2,6 +2,9 @@ import { GenericCallback } from "../models.mjs";
2
2
  import { Result } from "../result/models.mjs";
3
3
 
4
4
  //#region src/promise/models.d.ts
5
+ /**
6
+ * A promise that can be canceled
7
+ */
5
8
  declare class CancelablePromise<Value = void> extends Promise<Value> {
6
9
  #private;
7
10
  constructor(executor: (resolve: (value: Value) => void, reject: (reason: unknown) => void) => void);
@@ -11,8 +14,17 @@ declare class CancelablePromise<Value = void> extends Promise<Value> {
11
14
  */
12
15
  cancel(reason?: unknown): void;
13
16
  }
17
+ /**
18
+ * A promise that was fulfilled
19
+ */
14
20
  type FulfilledPromise<Value> = {
21
+ /**
22
+ * Status of the promise
23
+ */
15
24
  status: typeof PROMISE_TYPE_FULFILLED;
25
+ /**
26
+ * Value of the promise
27
+ */
16
28
  value: Awaited<Value>;
17
29
  };
18
30
  type PromiseData = {
@@ -23,6 +35,9 @@ type PromiseHandlers = {
23
35
  resolve: (value: unknown[]) => void;
24
36
  reject: (reason: unknown) => void;
25
37
  };
38
+ /**
39
+ * Options for a promise-handling function
40
+ */
26
41
  type PromiseOptions = {
27
42
  /**
28
43
  * AbortSignal for aborting the promise; when aborted, the promise will reject with the reason of the signal
@@ -51,20 +66,41 @@ type PromiseParameters = {
51
66
  * - Returns an array of values
52
67
  */
53
68
  type PromiseStrategy = 'complete' | 'first';
69
+ /**
70
+ * An error thrown when a promise times out
71
+ */
54
72
  declare class PromiseTimeoutError extends Error {
55
73
  constructor();
56
74
  }
57
75
  type PromisesItems<Items extends unknown[]> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? Promise<Value> : never : Items[ItemsKey] extends Promise<infer Value> ? Promise<Value> : Promise<Items[ItemsKey]> };
76
+ /**
77
+ * Options for handling multiple promises
78
+ */
58
79
  type PromisesOptions = {
80
+ /**
81
+ * AbortSignal for aborting the promises; when aborted, the promises will reject with the reason of the signal
82
+ */
59
83
  signal?: AbortSignal;
84
+ /**
85
+ * Strategy for handling the promises; defaults to `complete`
86
+ */
60
87
  strategy?: PromiseStrategy;
61
88
  };
62
89
  type PromisesResult<Items extends unknown[]> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends Promise<infer Value> ? Result<Awaited<Value>> : never };
63
90
  type PromisesUnwrapped<Items extends unknown[]> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? Awaited<Value> : never : Items[ItemsKey] extends Promise<infer Value> ? Awaited<Value> : never };
64
91
  type PromisesValue<Value> = FulfilledPromise<Value> | RejectedPromise;
65
92
  type PromisesValues<Items extends unknown[]> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? PromisesValue<Awaited<Value>> : never : Items[ItemsKey] extends Promise<infer Value> ? PromisesValue<Awaited<Value>> : never };
93
+ /**
94
+ * A promise that was rejected
95
+ */
66
96
  type RejectedPromise = {
97
+ /**
98
+ * Status of the promise
99
+ */
67
100
  status: typeof PROMISE_TYPE_REJECTED;
101
+ /**
102
+ * Reason for the rejection
103
+ */
68
104
  reason: unknown;
69
105
  };
70
106
  declare const PROMISE_ABORT_EVENT = "abort";
@@ -1,4 +1,7 @@
1
1
  //#region src/promise/models.ts
2
+ /**
3
+ * A promise that can be canceled
4
+ */
2
5
  var CancelablePromise = class extends Promise {
3
6
  #rejector;
4
7
  constructor(executor) {
@@ -17,6 +20,9 @@ var CancelablePromise = class extends Promise {
17
20
  this.#rejector(reason);
18
21
  }
19
22
  };
23
+ /**
24
+ * An error thrown when a promise times out
25
+ */
20
26
  var PromiseTimeoutError = class extends Error {
21
27
  constructor() {
22
28
  super(PROMISE_MESSAGE_TIMEOUT);