@oscarpalmer/atoms 0.186.2 → 0.187.1

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 (230) hide show
  1. package/dist/array/filter.d.mts +4 -4
  2. package/dist/array/find.d.mts +4 -4
  3. package/dist/array/first.d.mts +4 -4
  4. package/dist/array/get.d.mts +27 -1
  5. package/dist/array/get.mjs +5 -3
  6. package/dist/array/group-by.d.mts +6 -6
  7. package/dist/array/last.d.mts +4 -4
  8. package/dist/array/match.d.mts +7 -6
  9. package/dist/array/move.d.mts +7 -7
  10. package/dist/array/move.mjs +1 -1
  11. package/dist/array/select.d.mts +1 -0
  12. package/dist/array/slice.d.mts +3 -3
  13. package/dist/array/sort.d.mts +10 -7
  14. package/dist/array/sort.mjs +4 -3
  15. package/dist/array/swap.d.mts +1 -1
  16. package/dist/array/swap.mjs +1 -1
  17. package/dist/array/to-map.d.mts +32 -32
  18. package/dist/array/to-record.d.mts +6 -6
  19. package/dist/array/to-set.d.mts +6 -6
  20. package/dist/beacon.d.mts +6 -0
  21. package/dist/beacon.mjs +3 -0
  22. package/dist/color/index.d.mts +6 -2
  23. package/dist/color/index.mjs +6 -2
  24. package/dist/color/instance.d.mts +78 -14
  25. package/dist/color/instance.mjs +78 -14
  26. package/dist/color/misc/get.d.mts +39 -11
  27. package/dist/color/misc/get.mjs +39 -11
  28. package/dist/color/misc/is.d.mts +26 -11
  29. package/dist/color/misc/is.mjs +26 -11
  30. package/dist/color/misc/state.mjs +1 -1
  31. package/dist/color/models.d.mts +7 -4
  32. package/dist/color/space/hex.d.mts +15 -6
  33. package/dist/color/space/hex.mjs +15 -6
  34. package/dist/color/space/hsl.d.mts +10 -4
  35. package/dist/color/space/hsl.mjs +10 -4
  36. package/dist/color/space/rgb.d.mts +21 -12
  37. package/dist/color/space/rgb.mjs +21 -12
  38. package/dist/function/assert.d.mts +20 -14
  39. package/dist/function/assert.mjs +19 -13
  40. package/dist/function/limit.d.mts +8 -6
  41. package/dist/function/limit.mjs +8 -6
  42. package/dist/function/memoize.d.mts +15 -4
  43. package/dist/function/memoize.mjs +18 -4
  44. package/dist/function/once.d.mts +5 -3
  45. package/dist/function/once.mjs +5 -3
  46. package/dist/function/retry.d.mts +5 -2
  47. package/dist/function/retry.mjs +3 -1
  48. package/dist/function/work.d.mts +146 -98
  49. package/dist/{kalas.d.mts → herald.d.mts} +17 -8
  50. package/dist/{kalas.mjs → herald.mjs} +22 -13
  51. package/dist/index.d.mts +1464 -708
  52. package/dist/index.mjs +703 -342
  53. package/dist/internal/array/index-of.d.mts +4 -4
  54. package/dist/internal/array/insert.mjs +1 -1
  55. package/dist/internal/array/shuffle.d.mts +1 -0
  56. package/dist/internal/array/shuffle.mjs +2 -1
  57. package/dist/internal/is.d.mts +26 -8
  58. package/dist/internal/is.mjs +26 -8
  59. package/dist/internal/math/aggregate.d.mts +9 -9
  60. package/dist/internal/number.d.mts +13 -2
  61. package/dist/internal/number.mjs +13 -2
  62. package/dist/internal/random.d.mts +4 -2
  63. package/dist/internal/random.mjs +7 -5
  64. package/dist/internal/result.d.mts +17 -11
  65. package/dist/internal/result.mjs +10 -14
  66. package/dist/internal/string.d.mts +16 -1
  67. package/dist/internal/string.mjs +24 -1
  68. package/dist/internal/value/compare.d.mts +5 -2
  69. package/dist/internal/value/compare.mjs +5 -2
  70. package/dist/internal/value/equal.d.mts +12 -3
  71. package/dist/internal/value/equal.mjs +7 -4
  72. package/dist/internal/value/get.d.mts +17 -17
  73. package/dist/internal/value/has.d.mts +55 -11
  74. package/dist/internal/value/set.d.mts +24 -0
  75. package/dist/internal/value/set.mjs +1 -1
  76. package/dist/is.d.mts +12 -0
  77. package/dist/is.mjs +16 -1
  78. package/dist/logger.d.mts +7 -6
  79. package/dist/logger.mjs +6 -5
  80. package/dist/math.d.mts +36 -18
  81. package/dist/math.mjs +6 -3
  82. package/dist/models.d.mts +3 -3
  83. package/dist/promise/delay.d.mts +2 -0
  84. package/dist/promise/helpers.d.mts +6 -4
  85. package/dist/promise/helpers.mjs +6 -4
  86. package/dist/promise/index.d.mts +49 -38
  87. package/dist/promise/misc.d.mts +10 -7
  88. package/dist/promise/misc.mjs +4 -3
  89. package/dist/promise/models.d.mts +18 -19
  90. package/dist/promise/models.mjs +4 -3
  91. package/dist/promise/timed.d.mts +8 -6
  92. package/dist/query.d.mts +2 -0
  93. package/dist/query.mjs +27 -17
  94. package/dist/queue.d.mts +15 -4
  95. package/dist/queue.mjs +10 -3
  96. package/dist/random.d.mts +9 -2
  97. package/dist/random.mjs +7 -2
  98. package/dist/result/index.d.mts +14 -8
  99. package/dist/result/match.d.mts +18 -10
  100. package/dist/result/misc.d.mts +14 -7
  101. package/dist/result/misc.mjs +4 -2
  102. package/dist/result/models.d.mts +2 -0
  103. package/dist/result/work/flow.d.mts +86 -62
  104. package/dist/result/work/pipe.d.mts +55 -33
  105. package/dist/sized/map.d.mts +19 -16
  106. package/dist/sized/map.mjs +4 -4
  107. package/dist/sized/set.d.mts +20 -16
  108. package/dist/sized/set.mjs +8 -7
  109. package/dist/string/case.d.mts +8 -0
  110. package/dist/string/case.mjs +8 -0
  111. package/dist/string/fuzzy.d.mts +19 -5
  112. package/dist/string/fuzzy.mjs +7 -0
  113. package/dist/string/index.d.mts +17 -2
  114. package/dist/string/index.mjs +7 -9
  115. package/dist/string/match.d.mts +3 -0
  116. package/dist/string/match.mjs +3 -0
  117. package/dist/string/normalize.d.mts +6 -2
  118. package/dist/string/normalize.mjs +5 -2
  119. package/dist/string/template.d.mts +38 -9
  120. package/dist/string/template.mjs +19 -19
  121. package/dist/value/clone.d.mts +25 -4
  122. package/dist/value/clone.mjs +36 -22
  123. package/dist/value/collection.d.mts +9 -6
  124. package/dist/value/collection.mjs +3 -2
  125. package/dist/value/diff.d.mts +3 -1
  126. package/dist/value/diff.mjs +1 -0
  127. package/dist/value/freeze.d.mts +118 -9
  128. package/dist/value/freeze.mjs +56 -14
  129. package/dist/value/index.d.mts +1 -2
  130. package/dist/value/index.mjs +1 -2
  131. package/dist/value/merge.d.mts +11 -5
  132. package/dist/value/merge.mjs +2 -2
  133. package/dist/value/omit.d.mts +1 -0
  134. package/dist/value/omit.mjs +1 -0
  135. package/dist/value/pick.d.mts +1 -0
  136. package/dist/value/pick.mjs +1 -0
  137. package/dist/value/shake.d.mts +1 -0
  138. package/dist/value/shake.mjs +1 -0
  139. package/dist/value/smush.d.mts +1 -0
  140. package/dist/value/smush.mjs +1 -0
  141. package/dist/value/transform.d.mts +7 -3
  142. package/dist/value/unsmush.d.mts +1 -0
  143. package/dist/value/unsmush.mjs +1 -0
  144. package/package.json +12 -8
  145. package/src/array/filter.ts +4 -4
  146. package/src/array/find.ts +4 -4
  147. package/src/array/first.ts +4 -4
  148. package/src/array/get.ts +40 -5
  149. package/src/array/group-by.ts +6 -6
  150. package/src/array/last.ts +4 -4
  151. package/src/array/match.ts +7 -6
  152. package/src/array/move.ts +7 -7
  153. package/src/array/select.ts +1 -0
  154. package/src/array/slice.ts +3 -3
  155. package/src/array/sort.ts +15 -10
  156. package/src/array/swap.ts +1 -1
  157. package/src/array/to-map.ts +32 -32
  158. package/src/array/to-record.ts +6 -6
  159. package/src/array/to-set.ts +6 -6
  160. package/src/beacon.ts +6 -0
  161. package/src/color/index.ts +6 -2
  162. package/src/color/instance.ts +78 -14
  163. package/src/color/misc/get.ts +39 -11
  164. package/src/color/misc/is.ts +26 -11
  165. package/src/color/misc/state.ts +1 -1
  166. package/src/color/models.ts +7 -4
  167. package/src/color/space/hex.ts +15 -6
  168. package/src/color/space/hsl.ts +10 -4
  169. package/src/color/space/rgb.ts +21 -12
  170. package/src/function/assert.ts +20 -14
  171. package/src/function/limit.ts +8 -6
  172. package/src/function/memoize.ts +24 -5
  173. package/src/function/once.ts +5 -3
  174. package/src/function/retry.ts +7 -3
  175. package/src/function/work.ts +146 -98
  176. package/src/{kalas.ts → herald.ts} +23 -14
  177. package/src/index.ts +3 -2
  178. package/src/internal/array/index-of.ts +4 -4
  179. package/src/internal/array/insert.ts +1 -1
  180. package/src/internal/array/shuffle.ts +2 -1
  181. package/src/internal/is.ts +26 -8
  182. package/src/internal/math/aggregate.ts +9 -9
  183. package/src/internal/number.ts +13 -2
  184. package/src/internal/random.ts +10 -4
  185. package/src/internal/result.ts +30 -29
  186. package/src/internal/string.ts +28 -0
  187. package/src/internal/value/compare.ts +5 -2
  188. package/src/internal/value/equal.ts +13 -4
  189. package/src/internal/value/get.ts +17 -17
  190. package/src/internal/value/has.ts +54 -11
  191. package/src/internal/value/set.ts +25 -1
  192. package/src/is.ts +15 -1
  193. package/src/logger.ts +8 -7
  194. package/src/math.ts +36 -18
  195. package/src/models.ts +3 -3
  196. package/src/promise/delay.ts +2 -0
  197. package/src/promise/helpers.ts +6 -4
  198. package/src/promise/index.ts +49 -38
  199. package/src/promise/misc.ts +10 -7
  200. package/src/promise/models.ts +18 -19
  201. package/src/promise/timed.ts +8 -6
  202. package/src/query.ts +39 -28
  203. package/src/queue.ts +15 -4
  204. package/src/random.ts +8 -1
  205. package/src/result/index.ts +14 -8
  206. package/src/result/match.ts +18 -10
  207. package/src/result/misc.ts +17 -9
  208. package/src/result/models.ts +2 -0
  209. package/src/result/work/flow.ts +86 -62
  210. package/src/result/work/pipe.ts +55 -33
  211. package/src/sized/map.ts +20 -17
  212. package/src/sized/set.ts +21 -17
  213. package/src/string/case.ts +8 -0
  214. package/src/string/fuzzy.ts +19 -5
  215. package/src/string/index.ts +18 -15
  216. package/src/string/match.ts +3 -0
  217. package/src/string/normalize.ts +6 -2
  218. package/src/string/template.ts +69 -18
  219. package/src/value/clone.ts +51 -26
  220. package/src/value/collection.ts +9 -6
  221. package/src/value/diff.ts +3 -1
  222. package/src/value/freeze.ts +239 -25
  223. package/src/value/index.ts +0 -1
  224. package/src/value/merge.ts +11 -5
  225. package/src/value/omit.ts +1 -0
  226. package/src/value/pick.ts +1 -0
  227. package/src/value/shake.ts +1 -0
  228. package/src/value/smush.ts +1 -0
  229. package/src/value/transform.ts +7 -3
  230. package/src/value/unsmush.ts +1 -0
@@ -1,15 +1,29 @@
1
1
  //#region src/internal/string.d.ts
2
2
  /**
3
3
  * Get the string value from any value
4
+ *
4
5
  * @param value Original value
5
6
  * @returns String representation of the value
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * getString(null) // => ''
11
+ * getString('foo') // => 'foo'
12
+ * getString(123) // => '123'
13
+ * getString(true) // => 'true'
14
+ * getString([1, 2, 3]) // => '1,2,3'
15
+ * getString({a: 1}) // => '{"a":1}'
16
+ * getString(() => 123) // => '123'
17
+ * ```
6
18
  */
7
19
  declare function getString(value: unknown): string;
8
20
  declare function ignoreKey(key: string): boolean;
21
+ declare function interpolate(strings: TemplateStringsArray, values: unknown[]): string;
9
22
  /**
10
23
  * Join an array of values into a string _(while ignoring empty values)_
11
24
  *
12
25
  * _(`null`, `undefined`, and any values that become whitespace-only strings are considered empty)_
26
+ *
13
27
  * @param array Array of values
14
28
  * @param delimiter Delimiter to use between values
15
29
  * @returns Joined string
@@ -19,9 +33,10 @@ declare function tryDecode(value: string): string;
19
33
  declare function tryEncode(value: boolean | number | string): unknown;
20
34
  /**
21
35
  * Split a string into words _(and other readable parts)_
36
+ *
22
37
  * @param value Original string
23
38
  * @returns Array of words found in the string
24
39
  */
25
40
  declare function words(value: string): string[];
26
41
  //#endregion
27
- export { getString, ignoreKey, join, tryDecode, tryEncode, words };
42
+ export { getString, ignoreKey, interpolate, join, tryDecode, tryEncode, words };
@@ -1,8 +1,20 @@
1
1
  //#region src/internal/string.ts
2
2
  /**
3
3
  * Get the string value from any value
4
+ *
4
5
  * @param value Original value
5
6
  * @returns String representation of the value
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * getString(null) // => ''
11
+ * getString('foo') // => 'foo'
12
+ * getString(123) // => '123'
13
+ * getString(true) // => 'true'
14
+ * getString([1, 2, 3]) // => '1,2,3'
15
+ * getString({a: 1}) // => '{"a":1}'
16
+ * getString(() => 123) // => '123'
17
+ * ```
6
18
  */
7
19
  function getString(value) {
8
20
  if (typeof value === "string") return value;
@@ -15,10 +27,20 @@ function getString(value) {
15
27
  function ignoreKey(key) {
16
28
  return EXPRESSION_IGNORED.test(key);
17
29
  }
30
+ function interpolate(strings, values) {
31
+ const { length } = strings;
32
+ let interpolated = "";
33
+ for (let index = 0; index < length; index += 1) {
34
+ const value = values[index];
35
+ interpolated += `${strings[index]}${Array.isArray(value) ? join(value.map(getString)) : getString(value)}`;
36
+ }
37
+ return interpolated;
38
+ }
18
39
  /**
19
40
  * Join an array of values into a string _(while ignoring empty values)_
20
41
  *
21
42
  * _(`null`, `undefined`, and any values that become whitespace-only strings are considered empty)_
43
+ *
22
44
  * @param array Array of values
23
45
  * @param delimiter Delimiter to use between values
24
46
  * @returns Joined string
@@ -49,6 +71,7 @@ function tryEncode(value) {
49
71
  }
50
72
  /**
51
73
  * Split a string into words _(and other readable parts)_
74
+ *
52
75
  * @param value Original string
53
76
  * @returns Array of words found in the string
54
77
  */
@@ -58,4 +81,4 @@ function words(value) {
58
81
  const EXPRESSION_IGNORED = /(^|\.)(__proto__|constructor|prototype)(\.|$)/i;
59
82
  const EXPRESSION_WORDS = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
60
83
  //#endregion
61
- export { getString, ignoreKey, join, tryDecode, tryEncode, words };
84
+ export { getString, ignoreKey, interpolate, join, tryDecode, tryEncode, words };
@@ -4,6 +4,7 @@ import { Constructor, GenericCallback } from "../../models.mjs";
4
4
  type Comparator<Value = any> = (first: Value, second: Value) => number;
5
5
  /**
6
6
  * Compare two values _(for sorting purposes)_
7
+ *
7
8
  * @param first First value
8
9
  * @param second Second value
9
10
  * @returns `0` if equal; `-1` first comes before second; `1` first comes after second
@@ -21,14 +22,16 @@ declare namespace compare {
21
22
  /**
22
23
  * Deregister a custom comparison handler for a class
23
24
  *
24
- * Available as `deregisterComparator` and `compare.deregister`
25
+ * _Available as `deregisterComparator` and `compare.deregister`_
26
+ *
25
27
  * @param constructor Class constructor
26
28
  */
27
29
  declare function deregisterComparator<Instance>(constructor: Constructor<Instance>): void;
28
30
  /**
29
31
  * Register a custom comparison handler for a class
30
32
  *
31
- * Available as `registerComparator` and `compare.register`
33
+ * _Available as `registerComparator` and `compare.register`_
34
+ *
32
35
  * @param constructor Class constructor
33
36
  * @param handler Method name or comparison function _(defaults to `compare`)_
34
37
  */
@@ -5,6 +5,7 @@ import { getCompareHandlers } from "./handlers.mjs";
5
5
  const COMPARE_NAME = "compare";
6
6
  /**
7
7
  * Compare two values _(for sorting purposes)_
8
+ *
8
9
  * @param first First value
9
10
  * @param second Second value
10
11
  * @returns `0` if equal; `-1` first comes before second; `1` first comes after second
@@ -57,7 +58,8 @@ function compareValue(first, second, compareStrings) {
57
58
  /**
58
59
  * Deregister a custom comparison handler for a class
59
60
  *
60
- * Available as `deregisterComparator` and `compare.deregister`
61
+ * _Available as `deregisterComparator` and `compare.deregister`_
62
+ *
61
63
  * @param constructor Class constructor
62
64
  */
63
65
  function deregisterComparator(constructor) {
@@ -70,7 +72,8 @@ function getComparisonParts(value) {
70
72
  /**
71
73
  * Register a custom comparison handler for a class
72
74
  *
73
- * Available as `registerComparator` and `compare.register`
75
+ * _Available as `registerComparator` and `compare.register`_
76
+ *
74
77
  * @param constructor Class constructor
75
78
  * @param handler Method name or comparison function _(defaults to `compare`)_
76
79
  */
@@ -26,6 +26,7 @@ type EqualOptions = {
26
26
  type Equalizer = {
27
27
  /**
28
28
  * Are two strings equal?
29
+ *
29
30
  * @param first First string
30
31
  * @param second Second string
31
32
  * @param ignoreCase If `true`, comparison will be case-insensitive
@@ -34,6 +35,7 @@ type Equalizer = {
34
35
  (first: string, second: string, ignoreCase?: boolean): boolean;
35
36
  /**
36
37
  * Are two values equal?
38
+ *
37
39
  * @param first First value
38
40
  * @param second Second value
39
41
  * @returns `true` if the values are equal, otherwise `false`
@@ -41,11 +43,13 @@ type Equalizer = {
41
43
  (first: unknown, second: unknown): boolean;
42
44
  /**
43
45
  * Deregister a equality comparison handler for a specific class
46
+ *
44
47
  * @param constructor Class constructor
45
48
  */
46
49
  deregister: <Instance>(constructor: Constructor<Instance>) => void;
47
50
  /**
48
51
  * Register a equality comparison function for a specific class
52
+ *
49
53
  * @param constructor Class constructor
50
54
  * @param handler Comparison function
51
55
  */
@@ -54,12 +58,14 @@ type Equalizer = {
54
58
  /**
55
59
  * Deregister a equality comparison handler for a specific class
56
60
  *
57
- * Available as `deregisterEqualizer` and `equal.deregister`
61
+ * _Available as `deregisterEqualizer` and `equal.deregister`_
62
+ *
58
63
  * @param constructor Class constructor
59
64
  */
60
65
  declare function deregisterEqualizer<Instance>(constructor: Constructor<Instance>): void;
61
66
  /**
62
67
  * Are two strings equal?
68
+ *
63
69
  * @param first First string
64
70
  * @param second Second string
65
71
  * @param ignoreCase If `true`, comparison will be case-insensitive
@@ -68,6 +74,7 @@ declare function deregisterEqualizer<Instance>(constructor: Constructor<Instance
68
74
  declare function equal(first: string, second: string, ignoreCase?: boolean): boolean;
69
75
  /**
70
76
  * Are two values equal?
77
+ *
71
78
  * @param first First value
72
79
  * @param second Second value
73
80
  * @param options Comparison options
@@ -87,7 +94,8 @@ declare namespace equal {
87
94
  /**
88
95
  * Create an equalizer with predefined options
89
96
  *
90
- * Available as `initializeEqualizer` and `equal.initialize`
97
+ * _Available as `initializeEqualizer` and `equal.initialize`_
98
+ *
91
99
  * @param options Comparison options
92
100
  * @returns Equalizer function
93
101
  */
@@ -95,7 +103,8 @@ declare function initializeEqualizer(options?: EqualOptions): Equalizer;
95
103
  /**
96
104
  * Register a equality comparison function for a specific class
97
105
  *
98
- * Available as `registerEqualizer` and `equal.register`
106
+ * _Available as `registerEqualizer` and `equal.register`_
107
+ *
99
108
  * @param constructor Class constructor
100
109
  * @param handler Comparison function
101
110
  */
@@ -4,7 +4,8 @@ import { getCompareHandlers } from "./handlers.mjs";
4
4
  /**
5
5
  * Deregister a equality comparison handler for a specific class
6
6
  *
7
- * Available as `deregisterEqualizer` and `equal.deregister`
7
+ * _Available as `deregisterEqualizer` and `equal.deregister`_
8
+ *
8
9
  * @param constructor Class constructor
9
10
  */
10
11
  function deregisterEqualizer(constructor) {
@@ -102,7 +103,7 @@ function equalValue(first, second, options) {
102
103
  case typeof first !== typeof second: return false;
103
104
  case typeof first === "string" && options.ignoreCase === true: return Object.is(first.toLocaleLowerCase(), second.toLocaleLowerCase());
104
105
  case first instanceof ArrayBuffer && second instanceof ArrayBuffer: return equalArrayBuffer(first, second, options);
105
- case first instanceof Date && second instanceof Date: return Object.is(Number(first), Number(second));
106
+ case first instanceof Date && second instanceof Date: return Object.is(first.getTime(), second.getTime());
106
107
  case first instanceof DataView && second instanceof DataView: return equalDataView(first, second, options);
107
108
  case first instanceof Error && second instanceof Error: return equalProperties(first, second, ERROR_PROPERTIES, options);
108
109
  case first instanceof Map && second instanceof Map: return equalMap(first, second, options);
@@ -143,7 +144,8 @@ function getEqualOptions(input) {
143
144
  /**
144
145
  * Create an equalizer with predefined options
145
146
  *
146
- * Available as `initializeEqualizer` and `equal.initialize`
147
+ * _Available as `initializeEqualizer` and `equal.initialize`_
148
+ *
147
149
  * @param options Comparison options
148
150
  * @returns Equalizer function
149
151
  */
@@ -157,7 +159,8 @@ function initializeEqualizer(options) {
157
159
  /**
158
160
  * Register a equality comparison function for a specific class
159
161
  *
160
- * Available as `registerEqualizer` and `equal.register`
162
+ * _Available as `registerEqualizer` and `equal.register`_
163
+ *
161
164
  * @param constructor Class constructor
162
165
  * @param handler Comparison function
163
166
  */
@@ -4,38 +4,38 @@ import { NestedKeys, NestedValue, PlainObject } from "../../models.mjs";
4
4
  /**
5
5
  * Get the value from an object using a known path
6
6
  *
7
+ * @param data Object to get value from
8
+ * @param path Path for value
9
+ * @returns Found value, or `undefined`
10
+ *
7
11
  * @example
8
12
  * ```typescript
9
13
  * const data = {foo: {bar: {baz: 42}}};
10
14
  *
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
+ * getValue(data, 'foo'); // => {bar: {baz: 42}}
16
+ * getValue(data, 'foo.bar'); // => {baz: 42}
17
+ * getValue(data, 'foo.bar.baz'); // => 42
18
+ * getValue(data, 'foo.nope'); // => undefined
15
19
  * ```
16
- *
17
- * @param data Object to get value from
18
- * @param path Path for value
19
- * @returns Found value, or `undefined`
20
20
  */
21
21
  declare function getValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): NestedValue<Data, Path>;
22
22
  /**
23
23
  * Get the value from an object using an unknown path
24
24
  *
25
+ * @param data Object to get value from
26
+ * @param path Path for value
27
+ * @param ignoreCase If `true`, path matching is case-insensitive
28
+ * @returns Found value, or `undefined`
29
+ *
25
30
  * @example
26
31
  * ```typescript
27
32
  * const data = {foo: {bar: {baz: 42}}};
28
33
  *
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
34
+ * getValue(data, 'foo'); // => {bar: {baz: 42}}
35
+ * getValue(data, 'foo.bar'); // => {baz: 42}
36
+ * getValue(data, 'Foo.Bar.Baz', true); // => 42
37
+ * getValue(data, 'foo.nope'); // => undefined
33
38
  * ```
34
- *
35
- * @param data Object to get value from
36
- * @param path Path for value
37
- * @param ignoreCase If `true`, path matching is case-insensitive
38
- * @returns Found value, or `undefined`
39
39
  */
40
40
  declare function getValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): unknown;
41
41
  //#endregion
@@ -3,41 +3,85 @@ import { Result } from "../../result/models.mjs";
3
3
 
4
4
  //#region src/internal/value/has.d.ts
5
5
  /**
6
- * Check if a nested property is defined in an object
6
+ * Check if a property is defined in an object
7
+ *
7
8
  * @param data Object to check in
8
- * @param path Path for property
9
+ * @param path Path for property, e.g., `foo.bar.baz`
9
10
  * @returns `true` if the property exists, `false` otherwise
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const data = {foo: {bar: {baz: 42}}};
15
+ *
16
+ * hasValue(data, 'foo'); // => true
17
+ * hasValue(data, 'foo.bar'); // => true
18
+ * hasValue(data, 'foo.bar.baz'); // => true
19
+ * hasValue(data, 'foo.nope'); // => false
20
+ * ```
10
21
  */
11
22
  declare function hasValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): boolean;
12
23
  /**
13
- * Check if a nested property is defined in an object
24
+ * Check if a property is defined in an object
25
+ *
14
26
  * @param data Object to check in
15
- * @param path Path for property
27
+ * @param path Path for property, e.g., `foo.bar.baz`
16
28
  * @param ignoreCase If `true`, the path matching is case-insensitive
17
29
  * @returns `true` if the property exists, `false` otherwise
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const data = {foo: {bar: {baz: 42}}};
34
+ *
35
+ * hasValue(data, 'foo'); // => true
36
+ * hasValue(data, 'foo.bar'); // => true
37
+ * hasValue(data, 'Foo.Bar.Baz', true); // => true
38
+ * hasValue(data, 'foo.nope'); // => false
39
+ * ```
18
40
  */
19
41
  declare function hasValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): boolean;
20
42
  declare namespace hasValue {
21
43
  var get: typeof hasValueResult;
22
44
  }
23
45
  /**
24
- * Check if a nested property is defined in an object, and get its value if it is
46
+ * Check if a property is defined in an object, and get its value if it is
47
+ *
48
+ * _Available as `hasValueResult` and `hasValue.get`_
25
49
  *
26
- * Available as `hasValueResult` and `hasValue.get`
27
50
  * @param data Object to check in
28
- * @param path Path for property
51
+ * @param path Path for property, e.g., `foo.bar.baz`
29
52
  * @param ignoreCase If `true`, the path matching is case-insensitive
30
53
  * @returns Result object
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const data = {foo: {bar: {baz: 42}}};
58
+ *
59
+ * hasValueResult(data, 'foo'); // => {ok: true, value: {bar: {baz: 42}}}
60
+ * hasValueResult(data, 'foo.bar'); // => {ok: true, value: {baz: 42}}
61
+ * hasValueResult(data, 'foo.bar.baz'); // => {ok: true, value: 42}
62
+ * hasValueResult(data, 'foo.nope'); // => {ok: false, error: 'Expected property to exist in object'}
63
+ * ```
31
64
  */
32
- declare function hasValueResult<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path, ignoreCase?: boolean): Result<NestedValue<Data, ToString<Path>>, string>;
65
+ declare function hasValueResult<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): Result<NestedValue<Data, ToString<Path>>, string>;
33
66
  /**
34
- * Check if a nested property is defined in an object, and get its value if it is
67
+ * Check if a property is defined in an object, and get its value if it is
68
+ *
69
+ * _Available as `hasValueResult` and `hasValue.get`_
35
70
  *
36
- * Available as `hasValueResult` and `hasValue.get`
37
71
  * @param data Object to check in
38
- * @param path Path for property
72
+ * @param path Path for property, e.g., `foo.bar.baz`
39
73
  * @param ignoreCase If `true`, the path matching is case-insensitive
40
74
  * @returns Result object
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const data = {foo: {bar: {baz: 42}}};
79
+ *
80
+ * hasValueResult(data, 'foo'); // => {ok: true, value: {bar: {baz: 42}}}
81
+ * hasValueResult(data, 'foo.bar'); // => {ok: true, value: {baz: 42}}
82
+ * hasValueResult(data, 'Foo.Bar.Baz', true); // => {ok: true, value: 42}
83
+ * hasValueResult(data, 'foo.nope'); // => {ok: false, error: 'Expected property to exist in object'}
84
+ * ```
41
85
  */
42
86
  declare function hasValueResult<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): Result<unknown, string>;
43
87
  //#endregion
@@ -3,27 +3,51 @@ import { NestedKeys, NestedValue, PlainObject } from "../../models.mjs";
3
3
  //#region src/internal/value/set.d.ts
4
4
  /**
5
5
  * Update the value in an object using a known path
6
+ *
6
7
  * @param data Object to set value in
7
8
  * @param path Path for value, e.g., `foo.bar.baz`
8
9
  * @param updater Function to update the current value
9
10
  * @returns Updated object
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const data = {foo: {bar: {baz: 42}}};
15
+ *
16
+ * setValue(data, 'foo.bar.baz', (current) => current + 1); // => {foo: {bar: {baz: 43}}}
17
+ * ```
10
18
  */
11
19
  declare function setValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path, updater: (current: NestedValue<Data, Path>) => NestedValue<Data, Path>): Data;
12
20
  /**
13
21
  * Set the value in an object using a known path
22
+ *
14
23
  * @param data Object to set value in
15
24
  * @param path Path for value, e.g., `foo.bar.baz`
16
25
  * @param value Value to set
17
26
  * @returns Updated object
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const data = {foo: {bar: {baz: 42}}};
31
+ *
32
+ * setValue(data, 'foo.bar.baz', 99); // => {foo: {bar: {baz: 99}}}
33
+ * ```
18
34
  */
19
35
  declare function setValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path, value: NestedValue<Data, Path>): Data;
20
36
  /**
21
37
  * Set the value in an object using an unknown path
38
+ *
22
39
  * @param data Object to set value in
23
40
  * @param path Path for value, e.g., `foo.bar.baz`
24
41
  * @param value Value to set
25
42
  * @param ignoreCase If `true`, the path matching is case-insensitive
26
43
  * @returns Updated object
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const data = {foo: {bar: {baz: 42}}};
48
+ *
49
+ * setValue(data, 'Foo.Bar.Baz', 99, true); // => {foo: {bar: {baz: 99}}}
50
+ * ```
27
51
  */
28
52
  declare function setValue<Data extends PlainObject>(data: Data, path: string, value: unknown, ignoreCase?: boolean): Data;
29
53
  //#endregion
@@ -20,7 +20,7 @@ function setValue(data, path, value, ignoreCase) {
20
20
  let next = handleValue(target, currentPath, null, true, shouldIgnoreCase).value;
21
21
  if (typeof next !== "object" || next === null) {
22
22
  const nextPath = paths[index + 1];
23
- if (EXPRESSION_INDEX.test(nextPath)) next = Array.from({ length: Number.parseInt(nextPath, 10) + 1 }, () => void 0);
23
+ if (EXPRESSION_INDEX.test(nextPath)) next = Array.from({ length: Number(nextPath) + 1 }, () => void 0);
24
24
  else next = {};
25
25
  target[currentPath] = next;
26
26
  }
package/dist/is.d.mts CHANGED
@@ -3,72 +3,84 @@ import { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNonArrayOrP
3
3
  //#region src/is.d.ts
4
4
  /**
5
5
  * Is the value empty, or only containing `null` or `undefined` values?
6
+ *
6
7
  * @param value Value to check
7
8
  * @returns `true` if the value is considered empty, otherwise `false`
8
9
  */
9
10
  declare function isEmpty(value: unknown): boolean;
10
11
  /**
11
12
  * Is the value not empty, or holding non-empty values?
13
+ *
12
14
  * @param value Value to check
13
15
  * @returns `true` if the value is not considered empty, otherwise `false`
14
16
  */
15
17
  declare function isNonEmpty(value: unknown): boolean;
16
18
  /**
17
19
  * Is the value not `undefined` or `null`?
20
+ *
18
21
  * @param value Value to check
19
22
  * @returns `true` if the value is not `undefined` or `null`, otherwise `false`
20
23
  */
21
24
  declare function isNonNullable<Value>(value: Value): value is Exclude<Value, undefined | null>;
22
25
  /**
23
26
  * Is the value not `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
27
+ *
24
28
  * @param value Value to check
25
29
  * @returns `true` if the value is not `undefined`, `null`, or matches an empty string, otherwise `false`
26
30
  */
27
31
  declare function isNonNullableOrEmpty<Value>(value: Value): value is Exclude<Value, undefined | null | ''>;
28
32
  /**
29
33
  * Is the value not `undefined`, `null`, or stringified as a whitespace-only string?
34
+ *
30
35
  * @param value Value to check
31
36
  * @returns `true` if the value is not `undefined`, `null`, or matches a whitespace-only string, otherwise `false`
32
37
  */
33
38
  declare function isNonNullableOrWhitespace<Value>(value: Value): value is Exclude<Value, undefined | null | ''>;
34
39
  /**
35
40
  * Is the value not a number or a number-like string?
41
+ *
36
42
  * @param value Value to check
37
43
  * @returns `true` if the value is not a number or a number-like string, otherwise `false`
38
44
  */
39
45
  declare function isNonNumerical<Value>(value: Value): value is Exclude<Value, number | `${number}`>;
40
46
  /**
41
47
  * Is the value not an object _(or function)_?
48
+ *
42
49
  * @param value Value to check
43
50
  * @returns `true` if the value is not an object, otherwise `false`
44
51
  */
45
52
  declare function isNonObject<Value>(value: Value): value is Exclude<Value, object>;
46
53
  /**
47
54
  * Is the value `undefined` or `null`?
55
+ *
48
56
  * @param value Value to check
49
57
  * @returns `true` if the value is `undefined` or `null`, otherwise `false`
50
58
  */
51
59
  declare function isNullable(value: unknown): value is undefined | null;
52
60
  /**
53
61
  * Is the value `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
62
+ *
54
63
  * @param value Value to check
55
64
  * @returns `true` if the value is nullable or matches an empty string, otherwise `false`
56
65
  */
57
66
  declare function isNullableOrEmpty(value: unknown): value is undefined | null | '';
58
67
  /**
59
68
  * Is the value `undefined`, `null`, or stringified as a whitespace-only string?
69
+ *
60
70
  * @param value Value to check
61
71
  * @returns `true` if the value is nullable or matches a whitespace-only string, otherwise `false`
62
72
  */
63
73
  declare function isNullableOrWhitespace(value: unknown): value is undefined | null | '';
64
74
  /**
65
75
  * Is the value a number or a number-like string?
76
+ *
66
77
  * @param value Value to check
67
78
  * @returns `true` if the value is a number or a number-like string, otherwise `false`
68
79
  */
69
80
  declare function isNumerical(value: unknown): value is number | `${number}`;
70
81
  /**
71
82
  * Is the value an object _(or function)_?
83
+ *
72
84
  * @param value Value to check
73
85
  * @returns `true` if the value matches, otherwise `false`
74
86
  */
package/dist/is.mjs CHANGED
@@ -4,6 +4,7 @@ import { getString } from "./internal/string.mjs";
4
4
  //#region src/is.ts
5
5
  /**
6
6
  * Is the value empty, or only containing `null` or `undefined` values?
7
+ *
7
8
  * @param value Value to check
8
9
  * @returns `true` if the value is considered empty, otherwise `false`
9
10
  */
@@ -12,11 +13,15 @@ function isEmpty(value) {
12
13
  if (typeof value === "string") return value.length === 0;
13
14
  const values = getArray(value);
14
15
  const { length } = values;
15
- for (let index = 0; index < length; index += 1) if (values[index] != null) return false;
16
+ for (let index = 0; index < length; index += 1) {
17
+ const item = values[index];
18
+ if (Array.isArray(item) ? item[1] != null : item != null) return false;
19
+ }
16
20
  return true;
17
21
  }
18
22
  /**
19
23
  * Is the value not empty, or holding non-empty values?
24
+ *
20
25
  * @param value Value to check
21
26
  * @returns `true` if the value is not considered empty, otherwise `false`
22
27
  */
@@ -25,6 +30,7 @@ function isNonEmpty(value) {
25
30
  }
26
31
  /**
27
32
  * Is the value not `undefined` or `null`?
33
+ *
28
34
  * @param value Value to check
29
35
  * @returns `true` if the value is not `undefined` or `null`, otherwise `false`
30
36
  */
@@ -33,6 +39,7 @@ function isNonNullable(value) {
33
39
  }
34
40
  /**
35
41
  * Is the value not `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
42
+ *
36
43
  * @param value Value to check
37
44
  * @returns `true` if the value is not `undefined`, `null`, or matches an empty string, otherwise `false`
38
45
  */
@@ -41,6 +48,7 @@ function isNonNullableOrEmpty(value) {
41
48
  }
42
49
  /**
43
50
  * Is the value not `undefined`, `null`, or stringified as a whitespace-only string?
51
+ *
44
52
  * @param value Value to check
45
53
  * @returns `true` if the value is not `undefined`, `null`, or matches a whitespace-only string, otherwise `false`
46
54
  */
@@ -49,6 +57,7 @@ function isNonNullableOrWhitespace(value) {
49
57
  }
50
58
  /**
51
59
  * Is the value not a number or a number-like string?
60
+ *
52
61
  * @param value Value to check
53
62
  * @returns `true` if the value is not a number or a number-like string, otherwise `false`
54
63
  */
@@ -57,6 +66,7 @@ function isNonNumerical(value) {
57
66
  }
58
67
  /**
59
68
  * Is the value not an object _(or function)_?
69
+ *
60
70
  * @param value Value to check
61
71
  * @returns `true` if the value is not an object, otherwise `false`
62
72
  */
@@ -65,6 +75,7 @@ function isNonObject(value) {
65
75
  }
66
76
  /**
67
77
  * Is the value `undefined` or `null`?
78
+ *
68
79
  * @param value Value to check
69
80
  * @returns `true` if the value is `undefined` or `null`, otherwise `false`
70
81
  */
@@ -73,6 +84,7 @@ function isNullable(value) {
73
84
  }
74
85
  /**
75
86
  * Is the value `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
87
+ *
76
88
  * @param value Value to check
77
89
  * @returns `true` if the value is nullable or matches an empty string, otherwise `false`
78
90
  */
@@ -81,6 +93,7 @@ function isNullableOrEmpty(value) {
81
93
  }
82
94
  /**
83
95
  * Is the value `undefined`, `null`, or stringified as a whitespace-only string?
96
+ *
84
97
  * @param value Value to check
85
98
  * @returns `true` if the value is nullable or matches a whitespace-only string, otherwise `false`
86
99
  */
@@ -89,6 +102,7 @@ function isNullableOrWhitespace(value) {
89
102
  }
90
103
  /**
91
104
  * Is the value a number or a number-like string?
105
+ *
92
106
  * @param value Value to check
93
107
  * @returns `true` if the value is a number or a number-like string, otherwise `false`
94
108
  */
@@ -97,6 +111,7 @@ function isNumerical(value) {
97
111
  }
98
112
  /**
99
113
  * Is the value an object _(or function)_?
114
+ *
100
115
  * @param value Value to check
101
116
  * @returns `true` if the value matches, otherwise `false`
102
117
  */