@oscarpalmer/atoms 0.186.2 → 0.187.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 (229) 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 +677 -324
  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/is.d.mts +12 -0
  76. package/dist/is.mjs +16 -1
  77. package/dist/logger.d.mts +7 -6
  78. package/dist/logger.mjs +6 -5
  79. package/dist/math.d.mts +36 -18
  80. package/dist/math.mjs +6 -3
  81. package/dist/models.d.mts +3 -3
  82. package/dist/promise/delay.d.mts +2 -0
  83. package/dist/promise/helpers.d.mts +6 -4
  84. package/dist/promise/helpers.mjs +6 -4
  85. package/dist/promise/index.d.mts +49 -38
  86. package/dist/promise/misc.d.mts +10 -7
  87. package/dist/promise/misc.mjs +4 -3
  88. package/dist/promise/models.d.mts +18 -19
  89. package/dist/promise/models.mjs +4 -3
  90. package/dist/promise/timed.d.mts +8 -6
  91. package/dist/query.d.mts +2 -0
  92. package/dist/query.mjs +2 -0
  93. package/dist/queue.d.mts +15 -4
  94. package/dist/queue.mjs +10 -3
  95. package/dist/random.d.mts +9 -2
  96. package/dist/random.mjs +7 -2
  97. package/dist/result/index.d.mts +14 -8
  98. package/dist/result/match.d.mts +18 -10
  99. package/dist/result/misc.d.mts +14 -7
  100. package/dist/result/misc.mjs +4 -2
  101. package/dist/result/models.d.mts +2 -0
  102. package/dist/result/work/flow.d.mts +86 -62
  103. package/dist/result/work/pipe.d.mts +55 -33
  104. package/dist/sized/map.d.mts +19 -16
  105. package/dist/sized/map.mjs +4 -4
  106. package/dist/sized/set.d.mts +20 -16
  107. package/dist/sized/set.mjs +8 -7
  108. package/dist/string/case.d.mts +8 -0
  109. package/dist/string/case.mjs +8 -0
  110. package/dist/string/fuzzy.d.mts +19 -5
  111. package/dist/string/fuzzy.mjs +7 -0
  112. package/dist/string/index.d.mts +17 -2
  113. package/dist/string/index.mjs +7 -9
  114. package/dist/string/match.d.mts +3 -0
  115. package/dist/string/match.mjs +3 -0
  116. package/dist/string/normalize.d.mts +6 -2
  117. package/dist/string/normalize.mjs +5 -2
  118. package/dist/string/template.d.mts +38 -9
  119. package/dist/string/template.mjs +19 -19
  120. package/dist/value/clone.d.mts +25 -4
  121. package/dist/value/clone.mjs +36 -22
  122. package/dist/value/collection.d.mts +9 -6
  123. package/dist/value/collection.mjs +3 -2
  124. package/dist/value/diff.d.mts +3 -1
  125. package/dist/value/diff.mjs +1 -0
  126. package/dist/value/freeze.d.mts +118 -9
  127. package/dist/value/freeze.mjs +56 -14
  128. package/dist/value/index.d.mts +1 -2
  129. package/dist/value/index.mjs +1 -2
  130. package/dist/value/merge.d.mts +11 -5
  131. package/dist/value/merge.mjs +2 -2
  132. package/dist/value/omit.d.mts +1 -0
  133. package/dist/value/omit.mjs +1 -0
  134. package/dist/value/pick.d.mts +1 -0
  135. package/dist/value/pick.mjs +1 -0
  136. package/dist/value/shake.d.mts +1 -0
  137. package/dist/value/shake.mjs +1 -0
  138. package/dist/value/smush.d.mts +1 -0
  139. package/dist/value/smush.mjs +1 -0
  140. package/dist/value/transform.d.mts +7 -3
  141. package/dist/value/unsmush.d.mts +1 -0
  142. package/dist/value/unsmush.mjs +1 -0
  143. package/package.json +11 -7
  144. package/src/array/filter.ts +4 -4
  145. package/src/array/find.ts +4 -4
  146. package/src/array/first.ts +4 -4
  147. package/src/array/get.ts +40 -5
  148. package/src/array/group-by.ts +6 -6
  149. package/src/array/last.ts +4 -4
  150. package/src/array/match.ts +7 -6
  151. package/src/array/move.ts +7 -7
  152. package/src/array/select.ts +1 -0
  153. package/src/array/slice.ts +3 -3
  154. package/src/array/sort.ts +15 -10
  155. package/src/array/swap.ts +1 -1
  156. package/src/array/to-map.ts +32 -32
  157. package/src/array/to-record.ts +6 -6
  158. package/src/array/to-set.ts +6 -6
  159. package/src/beacon.ts +6 -0
  160. package/src/color/index.ts +6 -2
  161. package/src/color/instance.ts +78 -14
  162. package/src/color/misc/get.ts +39 -11
  163. package/src/color/misc/is.ts +26 -11
  164. package/src/color/misc/state.ts +1 -1
  165. package/src/color/models.ts +7 -4
  166. package/src/color/space/hex.ts +15 -6
  167. package/src/color/space/hsl.ts +10 -4
  168. package/src/color/space/rgb.ts +21 -12
  169. package/src/function/assert.ts +20 -14
  170. package/src/function/limit.ts +8 -6
  171. package/src/function/memoize.ts +24 -5
  172. package/src/function/once.ts +5 -3
  173. package/src/function/retry.ts +7 -3
  174. package/src/function/work.ts +146 -98
  175. package/src/{kalas.ts → herald.ts} +23 -14
  176. package/src/index.ts +3 -2
  177. package/src/internal/array/index-of.ts +4 -4
  178. package/src/internal/array/insert.ts +1 -1
  179. package/src/internal/array/shuffle.ts +2 -1
  180. package/src/internal/is.ts +26 -8
  181. package/src/internal/math/aggregate.ts +9 -9
  182. package/src/internal/number.ts +13 -2
  183. package/src/internal/random.ts +10 -4
  184. package/src/internal/result.ts +30 -29
  185. package/src/internal/string.ts +28 -0
  186. package/src/internal/value/compare.ts +5 -2
  187. package/src/internal/value/equal.ts +13 -4
  188. package/src/internal/value/get.ts +17 -17
  189. package/src/internal/value/has.ts +54 -11
  190. package/src/internal/value/set.ts +24 -0
  191. package/src/is.ts +15 -1
  192. package/src/logger.ts +8 -7
  193. package/src/math.ts +36 -18
  194. package/src/models.ts +3 -3
  195. package/src/promise/delay.ts +2 -0
  196. package/src/promise/helpers.ts +6 -4
  197. package/src/promise/index.ts +49 -38
  198. package/src/promise/misc.ts +10 -7
  199. package/src/promise/models.ts +18 -19
  200. package/src/promise/timed.ts +8 -6
  201. package/src/query.ts +2 -0
  202. package/src/queue.ts +15 -4
  203. package/src/random.ts +8 -1
  204. package/src/result/index.ts +14 -8
  205. package/src/result/match.ts +18 -10
  206. package/src/result/misc.ts +17 -9
  207. package/src/result/models.ts +2 -0
  208. package/src/result/work/flow.ts +86 -62
  209. package/src/result/work/pipe.ts +55 -33
  210. package/src/sized/map.ts +20 -17
  211. package/src/sized/set.ts +21 -17
  212. package/src/string/case.ts +8 -0
  213. package/src/string/fuzzy.ts +19 -5
  214. package/src/string/index.ts +18 -15
  215. package/src/string/match.ts +3 -0
  216. package/src/string/normalize.ts +6 -2
  217. package/src/string/template.ts +69 -18
  218. package/src/value/clone.ts +51 -26
  219. package/src/value/collection.ts +9 -6
  220. package/src/value/diff.ts +3 -1
  221. package/src/value/freeze.ts +239 -25
  222. package/src/value/index.ts +0 -1
  223. package/src/value/merge.ts +11 -5
  224. package/src/value/omit.ts +1 -0
  225. package/src/value/pick.ts +1 -0
  226. package/src/value/shake.ts +1 -0
  227. package/src/value/smush.ts +1 -0
  228. package/src/value/transform.ts +7 -3
  229. package/src/value/unsmush.ts +1 -0
@@ -2,8 +2,8 @@ import { isArrayOrPlainObject, isTypedArray } from "../internal/is.mjs";
2
2
  import { getSelfHandlers } from "../internal/value/handlers.mjs";
3
3
  //#region src/value/clone.ts
4
4
  const CLONE_NAME = "clone";
5
- function clone(value) {
6
- return cloneValue(value, 0, /* @__PURE__ */ new WeakMap());
5
+ function clone(value, flat) {
6
+ return flat === true ? copy(value) : cloneValue(value, 0, /* @__PURE__ */ new WeakMap(), false);
7
7
  }
8
8
  clone.handlers = getSelfHandlers(clone, {
9
9
  callback: tryStructuredClone,
@@ -25,11 +25,11 @@ function cloneDataView(value, depth, references) {
25
25
  references.set(value, cloned);
26
26
  return cloned;
27
27
  }
28
- function cloneMap(map, depth, references) {
28
+ function cloneMap(map, depth, references, flat) {
29
29
  if (depth >= MAX_CLONE_DEPTH) return map;
30
30
  const cloned = /* @__PURE__ */ new Map();
31
31
  const entries = map.entries();
32
- for (const entry of entries) cloned.set(cloneValue(entry[0], depth + 1, references), cloneValue(entry[1], depth + 1, references));
32
+ for (const entry of entries) cloned.set(flat ? entry[0] : cloneValue(entry[0], depth + 1, references, false), flat ? entry[1] : cloneValue(entry[1], depth + 1, references, false));
33
33
  references.set(map, cloned);
34
34
  return cloned;
35
35
  }
@@ -39,14 +39,14 @@ function cloneNode(node, depth, references) {
39
39
  references.set(node, cloned);
40
40
  return cloned;
41
41
  }
42
- function clonePlainObject(value, depth, references) {
43
- if (depth >= MAX_CLONE_DEPTH) return Array.isArray(value) ? value.slice() : { ...value };
42
+ function cloneObject(value, depth, references, flat) {
43
+ if (flat || depth >= MAX_CLONE_DEPTH) return Array.isArray(value) ? value.slice() : { ...value };
44
44
  const cloned = Array.isArray(value) ? [] : {};
45
45
  const keys = [...Object.keys(value), ...Object.getOwnPropertySymbols(value)];
46
46
  const { length } = keys;
47
47
  for (let index = 0; index < length; index += 1) {
48
48
  const key = keys[index];
49
- cloned[key] = cloneValue(value[key], depth + 1, references);
49
+ cloned[key] = cloneValue(value[key], depth + 1, references, false);
50
50
  }
51
51
  references.set(value, cloned);
52
52
  return cloned;
@@ -58,12 +58,12 @@ function cloneRegularExpression(value, depth, references) {
58
58
  references.set(value, cloned);
59
59
  return cloned;
60
60
  }
61
- function cloneSet(set, depth, references) {
61
+ function cloneSet(set, depth, references, flat) {
62
62
  if (depth >= MAX_CLONE_DEPTH) return set;
63
63
  const cloned = /* @__PURE__ */ new Set();
64
64
  const values = [...set.values()];
65
65
  const { length } = values;
66
- for (let index = 0; index < length; index += 1) cloned.add(cloneValue(values[index], depth + 1, references));
66
+ for (let index = 0; index < length; index += 1) cloned.add(flat ? values[index] : cloneValue(values[index], depth + 1, references, false));
67
67
  references.set(set, cloned);
68
68
  return cloned;
69
69
  }
@@ -73,32 +73,45 @@ function cloneTypedArray(value, depth, references) {
73
73
  references.set(value, cloned);
74
74
  return cloned;
75
75
  }
76
- function cloneValue(value, depth, references) {
76
+ function cloneValue(value, depth, references, flat) {
77
77
  switch (true) {
78
- case value == null: return value;
79
- case typeof value === "bigint": return BigInt(value);
80
- case typeof value === "boolean": return Boolean(value);
78
+ case value == null:
79
+ case typeof value === "bigint":
80
+ case typeof value === "boolean":
81
+ case typeof value === "number":
82
+ case typeof value === "string": return value;
81
83
  case typeof value === "function": return;
82
- case typeof value === "number": return Number(value);
83
- case typeof value === "string": return String(value);
84
84
  case typeof value === "symbol": return Symbol(value.description);
85
85
  case references.has(value): return references.get(value);
86
86
  case value instanceof ArrayBuffer: return cloneArrayBuffer(value, depth, references);
87
87
  case value instanceof DataView: return cloneDataView(value, depth, references);
88
88
  case value instanceof Date: return new Date(value.getTime());
89
89
  case value instanceof RegExp: return cloneRegularExpression(value, depth, references);
90
- case value instanceof Map: return cloneMap(value, depth, references);
90
+ case value instanceof Map: return cloneMap(value, depth, references, flat);
91
91
  case typeof Node !== "undefined" && value instanceof Node: return cloneNode(value, depth, references);
92
- case value instanceof Set: return cloneSet(value, depth, references);
93
- case isArrayOrPlainObject(value): return clonePlainObject(value, depth, references);
92
+ case value instanceof Set: return cloneSet(value, depth, references, flat);
93
+ case isArrayOrPlainObject(value): return cloneObject(value, depth, references, flat);
94
94
  case isTypedArray(value): return cloneTypedArray(value, depth, references);
95
95
  default: return clone.handlers.handle(value, depth, references);
96
96
  }
97
97
  }
98
98
  /**
99
+ * Copy any kind of value
100
+ *
101
+ * - Clones the value shallowly, without cloning nested values
102
+ * - To copy a value deeply, use `clone` instead
103
+ *
104
+ * @param value Value to copy
105
+ * @returns Copied value
106
+ */
107
+ function copy(value) {
108
+ return cloneValue(value, 0, /* @__PURE__ */ new WeakMap(), true);
109
+ }
110
+ /**
99
111
  * Deregister a clone handler for a specific class
100
112
  *
101
- * Available as `deregisterCloner` and `template.deregister`
113
+ * _Available as `deregisterCloner` and `template.deregister`_
114
+ *
102
115
  * @param constructor Class constructor
103
116
  */
104
117
  function deregisterCloner(constructor) {
@@ -107,9 +120,10 @@ function deregisterCloner(constructor) {
107
120
  /**
108
121
  * Register a clone handler for a specific class
109
122
  *
110
- * Available as `registerCloner` and `template.register`
123
+ * _Available as `registerCloner` and `template.register`_
124
+ *
111
125
  * @param constructor Class constructor
112
- * @param handler Method name or clone function _(defaults to `clone`)_
126
+ * @param handler Method name or clone function _(defaults to method name `clone`)_
113
127
  */
114
128
  function registerCloner(constructor, handler) {
115
129
  clone.handlers.register(constructor, handler);
@@ -127,4 +141,4 @@ function tryStructuredClone(value, depth, references) {
127
141
  }
128
142
  const MAX_CLONE_DEPTH = 100;
129
143
  //#endregion
130
- export { clone, deregisterCloner, registerCloner };
144
+ export { clone, copy, deregisterCloner, registerCloner };
@@ -1,22 +1,25 @@
1
1
  //#region src/value/collection.d.ts
2
2
  /**
3
- * Does the value exist for a key in a map?
4
- * @param map Map to check in
3
+ * Does the value exist for a key in a _Map_?
4
+ *
5
+ * @param map _Map_ to check in
5
6
  * @param value Value to check for
6
7
  * @returns `true` if the value exists, otherwise `false`
7
8
  */
8
9
  declare function inMap<Value>(map: Map<unknown, Value>, value: Value): boolean;
9
10
  /**
10
- * Does the value exist for a key in a map?
11
- * @param map Map to check in
11
+ * Does the value exist for a key in a _Map_?
12
+ *
13
+ * @param map _Map_ to check in
12
14
  * @param value Value to check for
13
15
  * @param key To return the key for the value
14
16
  * @returns The key for the value if it exists, otherwise `undefined`
15
17
  */
16
18
  declare function inMap<Key, Value>(map: Map<Key, Value>, value: Value, key: true): Key;
17
19
  /**
18
- * Does the value exist in a set?
19
- * @param set Set to check in
20
+ * Does the value exist in a _Set_?
21
+ *
22
+ * @param set _Set_ to check in
20
23
  * @param value Value to check for
21
24
  * @returns `true` if the value exists, otherwise `false`
22
25
  */
@@ -7,8 +7,9 @@ function inMap(map, value, key) {
7
7
  for (const [key, item] of map) if (equal(item, value)) return key;
8
8
  }
9
9
  /**
10
- * Does the value exist in a set?
11
- * @param set Set to check in
10
+ * Does the value exist in a _Set_?
11
+ *
12
+ * @param set _Set_ to check in
12
13
  * @param value Value to check for
13
14
  * @returns `true` if the value exists, otherwise `false`
14
15
  */
@@ -21,7 +21,8 @@ type DiffResult<First, Second = First> = {
21
21
  */
22
22
  type: DiffType;
23
23
  /**
24
- * - The differences between the two values
24
+ * The differences between the two values
25
+ *
25
26
  * - Keys are in dot notation
26
27
  * - Values are objects with `from` and `to` properties
27
28
  */
@@ -43,6 +44,7 @@ type DiffValue<First = unknown, Second = First> = {
43
44
  };
44
45
  /**
45
46
  * Find the differences between two values
47
+ *
46
48
  * @param first First value
47
49
  * @param second Second value
48
50
  * @param options Comparison options
@@ -4,6 +4,7 @@ import { equal } from "../internal/value/equal.mjs";
4
4
  //#region src/value/diff.ts
5
5
  /**
6
6
  * Find the differences between two values
7
+ *
7
8
  * @param first First value
8
9
  * @param second Second value
9
10
  * @param options Comparison options
@@ -1,35 +1,144 @@
1
- import { ArrayOrPlainObject, GenericCallback, PlainObject } from "../models.mjs";
1
+ import { PlainObject } from "../models.mjs";
2
2
 
3
3
  //#region src/value/freeze.d.ts
4
4
  /**
5
5
  * A frozen value with readonly properties _(going as deep as possible)_
6
6
  */
7
- type Frozen<Value extends ArrayOrPlainObject> = { readonly [Key in keyof Value]: Value[Key] extends ArrayOrPlainObject ? Frozen<Value[Key]> : Value[Key] };
7
+ type Frozen<Value> = Value extends unknown[] ? Readonly<Value> : Value extends PlainObject ? { readonly [Key in keyof Value]: Frozen<Value[Key]> } : Value extends Map<infer Key, infer Value> ? ReadonlyMap<Key, Frozen<Value>> : Value extends Set<infer Item> ? ReadonlySet<Frozen<Item>> : Readonly<Value>;
8
8
  /**
9
- * Freeze an array and all its indices recursively
9
+ * Freeze an array and its indiced values, but not any nested values
10
+ *
11
+ * _Available as `flatFreeze` and `freeze.flat`_
12
+ *
13
+ * @param array Array to freeze
14
+ * @returns Frozen array
15
+ */
16
+ declare function flatFreeze<Item>(array: Item[]): ReadonlyArray<Item>;
17
+ /**
18
+ * Freeze a map and its values, but not any nested values
19
+ *
20
+ * _Available as `flatFreeze` and `freeze.flat`_
21
+ *
22
+ * @param map Map to freeze
23
+ * @returns Frozen map
24
+ */
25
+ declare function flatFreeze<Key, Value>(map: Map<Key, Value>): ReadonlyMap<Key, Value>;
26
+ /**
27
+ * Freeze an object and its properties, but not any nested values
28
+ *
29
+ * _Available as `flatFreeze` and `freeze.flat`_
30
+ *
31
+ * @param object Object to freeze
32
+ * @returns Frozen object
33
+ */
34
+ declare function flatFreeze<Value extends PlainObject>(object: Value): Readonly<Value>;
35
+ /**
36
+ * Freeze a set and its values, but not any nested values
37
+ *
38
+ * _Available as `flatFreeze` and `freeze.flat`_
39
+ *
40
+ * @param set Set to freeze
41
+ * @returns Frozen set
42
+ */
43
+ declare function flatFreeze<Item>(set: Set<Item>): ReadonlySet<Item>;
44
+ /**
45
+ * Freeze any value, if possible
46
+ *
47
+ * _(Only arrays, maps, plain objects, and sets are freezable)_
48
+ *
49
+ * _Available as `flatFreeze` and `freeze.flat`_
50
+ *
51
+ * @param value Value to freeze
52
+ * @returns Frozen value
53
+ */
54
+ declare function flatFreeze<Value>(value: Value): Value;
55
+ /**
56
+ * Freeze an array and its values _(but not any nested values)_, preventing modifications
57
+ *
58
+ * @param array Array to freeze
59
+ * @param flat Freeze _only_ the array, not any nested values
60
+ * @returns Frozen array
61
+ */
62
+ declare function freeze<Item>(array: Item[], flat: true): ReadonlyArray<Item>;
63
+ /**
64
+ * Freeze a map and its values _(but not any nested values)_, preventing modifications
65
+ *
66
+ * @param map Map to freeze
67
+ * @param flat Freeze _only_ the map, not any nested values
68
+ * @returns Frozen map
69
+ */
70
+ declare function freeze<Key, Value>(map: Map<Key, Value>, flat: true): ReadonlyMap<Key, Value>;
71
+ /**
72
+ * Freeze an object and its properties _(but not any nested values)_, preventing modifications
73
+ *
74
+ * @param object Object to freeze
75
+ * @param flat Freeze _only_ the object, not any nested values
76
+ * @returns Frozen object
77
+ */
78
+ declare function freeze<Value extends PlainObject>(object: Value, flat: true): Readonly<Value>;
79
+ /**
80
+ * Freeze a set and its values _(but not any nested values)_, preventing modifications
81
+ *
82
+ * @param set Set to freeze
83
+ * @param flat Freeze _only_ the set, not any nested values
84
+ * @returns Frozen set
85
+ */
86
+ declare function freeze<Item>(set: Set<Item>, flat: true): ReadonlySet<Item>;
87
+ /**
88
+ * Freeze an array and its values recursively, preventing modifications
89
+ *
90
+ * _(If you only want to freeze the array itself, but not any nested values, use `freeze(array, true)`, `freeze.flat(array)`, or `flatFreeze(array)` instead)_
91
+ *
10
92
  * @param array Array to freeze
11
93
  * @returns Frozen array
12
94
  */
13
95
  declare function freeze<Item>(array: Item[]): Frozen<Item[]>;
14
96
  /**
15
- * Freeze a function
16
- * @param fn Function to freeze
17
- * @returns Frozen function
97
+ * Freeze a map and its values recursively, preventing modifications
98
+ *
99
+ * _(If you only want to freeze the map itself, but not any nested values, use `freeze(map, true)`, `freeze.flat(map)`, or `flatFreeze(map)` instead)_
100
+ *
101
+ * @param map Map to freeze
102
+ * @returns Frozen map
18
103
  */
19
- declare function freeze<Fn extends GenericCallback>(fn: Fn): Readonly<Fn>;
104
+ declare function freeze<Key, Value>(map: Map<Key, Value>): Frozen<Map<Key, Value>>;
20
105
  /**
21
106
  * Freeze an object and all its properties recursively
107
+ *
108
+ * _(If you only want to freeze the object itself, but not any nested values, use `freeze(object, true)`, `freeze.flat(object)`, or `flatFreeze(object)` instead)_
109
+ *
22
110
  * @param object Object to freeze
23
111
  * @returns Frozen object
24
112
  */
25
113
  declare function freeze<Value extends PlainObject>(object: Value): Frozen<Value>;
114
+ /**
115
+ * Freeze a set and its values recursively
116
+ *
117
+ * _(If you only want to freeze the set itself, but not any nested values, use `freeze(set, true)`, `freeze.flat(set)`, or `flatFreeze(set)` instead)_
118
+ *
119
+ * @param set Set to freeze
120
+ * @returns Frozen set
121
+ */
122
+ declare function freeze<Item>(set: Set<Item>): Frozen<Set<Item>>;
26
123
  /**
27
124
  * Freeze any value, if possible
28
125
  *
29
- * _(Only arrays, functions, and plain objects are freezable)_
126
+ * _(Only arrays, maps, plain objects, and sets are freezable)_
127
+ *
30
128
  * @param value Value to freeze
31
129
  * @returns Frozen value
32
130
  */
33
131
  declare function freeze<Value>(value: Value): Value;
132
+ declare namespace freeze {
133
+ var flat: typeof flatFreeze;
134
+ var is: typeof isFrozen;
135
+ }
136
+ /**
137
+ * Is the value frozen?
138
+ *
139
+ * @param value Value to check
140
+ * @returns `true` if the value is frozen, otherwise `false`
141
+ */
142
+ declare function isFrozen(value: unknown): boolean;
34
143
  //#endregion
35
- export { Frozen, freeze };
144
+ export { Frozen, flatFreeze, freeze, isFrozen };
@@ -1,38 +1,80 @@
1
+ import { noop } from "../internal/function/misc.mjs";
1
2
  import { isPlainObject } from "../internal/is.mjs";
2
3
  //#region src/value/freeze.ts
3
- function freeze(value) {
4
- return freezeValue(value, /* @__PURE__ */ new WeakSet());
4
+ function fakeDelete() {
5
+ return false;
5
6
  }
6
- function freezeArray(array, references) {
7
+ function flatFreeze(value) {
8
+ return freezeValue(value, /* @__PURE__ */ new WeakSet(), true);
9
+ }
10
+ function freeze(value, flat) {
11
+ return freezeValue(value, /* @__PURE__ */ new WeakSet(), flat === true);
12
+ }
13
+ freeze.flat = flatFreeze;
14
+ freeze.is = isFrozen;
15
+ function freezeArray(array, references, flat) {
16
+ if (flat) return Object.freeze(array);
7
17
  references.add(array);
8
18
  const { length } = array;
9
19
  for (let index = 0; index < length; index += 1) {
10
20
  const value = array[index];
11
- if (!references.has(value)) array[index] = freezeValue(array[index], references);
21
+ if (!references.has(value)) array[index] = freezeValue(array[index], references, false);
12
22
  }
13
23
  return Object.freeze(array);
14
24
  }
15
- function freezeFunction(fn, references) {
16
- references.add(fn);
17
- return Object.freeze(fn);
25
+ function freezeMap(map, references, flat) {
26
+ frozenValues.add(map);
27
+ map.clear = noop;
28
+ map.delete = fakeDelete;
29
+ map.set = () => map;
30
+ if (flat) return map;
31
+ references.add(map);
32
+ const entries = map.entries();
33
+ for (const [key, value] of entries) if (!references.has(value)) map.set(key, freezeValue(value, references, false));
34
+ return map;
18
35
  }
19
- function freezeObject(object, references) {
36
+ function freezeObject(object, references, flat) {
37
+ if (flat) return Object.freeze(object);
20
38
  references.add(object);
21
39
  const keys = Object.keys(object);
22
40
  const { length } = keys;
23
41
  for (let index = 0; index < length; index += 1) {
24
42
  const key = keys[index];
25
- if (!references.has(object[key])) object[key] = freezeValue(object[key], references);
43
+ if (!references.has(object[key])) object[key] = freezeValue(object[key], references, false);
26
44
  }
27
45
  return Object.freeze(object);
28
46
  }
29
- function freezeValue(value, references) {
47
+ function freezeSet(set, references, flat) {
48
+ frozenValues.add(set);
49
+ set.clear = noop;
50
+ set.delete = fakeDelete;
51
+ set.add = () => set;
52
+ if (flat) return set;
53
+ references.add(set);
54
+ const values = set.values();
55
+ for (const value of values) if (!references.has(value)) set.add(freezeValue(value, references, false));
56
+ return set;
57
+ }
58
+ function freezeValue(value, references, flat) {
30
59
  switch (true) {
31
- case typeof value === "function": return freezeFunction(value, references);
32
- case Array.isArray(value): return freezeArray(value, references);
33
- case isPlainObject(value): return freezeObject(value, references);
60
+ case isFrozen(value): return value;
61
+ case value instanceof Map: return freezeMap(value, references, flat);
62
+ case value instanceof Set: return freezeSet(value, references, flat);
63
+ case Array.isArray(value): return freezeArray(value, references, flat);
64
+ case isPlainObject(value): return freezeObject(value, references, flat);
34
65
  default: return value;
35
66
  }
36
67
  }
68
+ /**
69
+ * Is the value frozen?
70
+ *
71
+ * @param value Value to check
72
+ * @returns `true` if the value is frozen, otherwise `false`
73
+ */
74
+ function isFrozen(value) {
75
+ if (value instanceof Map || value instanceof Set) return frozenValues.has(value);
76
+ return typeof value === "object" && value !== null && Object.isFrozen(value);
77
+ }
78
+ const frozenValues = /* @__PURE__ */ new WeakSet();
37
79
  //#endregion
38
- export { freeze };
80
+ export { flatFreeze, freeze, isFrozen };
@@ -1,7 +1,6 @@
1
- import { Frozen, freeze } from "./freeze.mjs";
2
1
  import { omit } from "./omit.mjs";
3
2
  import { pick } from "./pick.mjs";
4
3
  import { Shaken, shake } from "./shake.mjs";
5
4
  import { Smushed, smush } from "./smush.mjs";
6
5
  import { Unsmushed, unsmush } from "./unsmush.mjs";
7
- export { type Frozen, type Shaken, type Smushed, type Unsmushed, freeze, omit, pick, shake, smush, unsmush };
6
+ export { type Shaken, type Smushed, type Unsmushed, omit, pick, shake, smush, unsmush };
@@ -1,7 +1,6 @@
1
- import { freeze } from "./freeze.mjs";
2
1
  import { omit } from "./omit.mjs";
3
2
  import { pick } from "./pick.mjs";
4
3
  import { shake } from "./shake.mjs";
5
4
  import { smush } from "./smush.mjs";
6
5
  import { unsmush } from "./unsmush.mjs";
7
- export { freeze, omit, pick, shake, smush, unsmush };
6
+ export { omit, pick, shake, smush, unsmush };
@@ -5,6 +5,9 @@ import { ArrayOrPlainObject, NestedPartial, PlainObject, UnionToIntersection } f
5
5
  * Options for assigning values
6
6
  */
7
7
  type AssignOptions = Omit<MergeOptions, 'assignValues'>;
8
+ /**
9
+ * An assigner function for assigning values from one or more objects to the first one
10
+ */
8
11
  type Assigner = {
9
12
  /**
10
13
  * Assign values from one or more objects to the first one
@@ -27,7 +30,7 @@ type MergeOptions = {
27
30
  * Key _(or key epxressions)_ for values that should be replaced
28
31
  *
29
32
  * ```ts
30
- * merge([{items: [1, 2, 3]}, {items: [99]}]); // {items: [99]}
33
+ * merge([{items: [1, 2, 3]}, {items: [99]}]); // => {items: [99]}
31
34
  * ```
32
35
  */
33
36
  replaceableObjects?: string | RegExp | Array<string | RegExp>;
@@ -35,7 +38,7 @@ type MergeOptions = {
35
38
  * Skip nullable values when merging objects?
36
39
  *
37
40
  * ```ts
38
- * merge({a: 1, b: 2}, {b: null, c: 3}, {d: null}); // {a: 1, b: 2, c: 3}
41
+ * merge({a: 1, b: 2}, {b: null, c: 3}, {d: null}); // => {a: 1, b: 2, c: 3}
39
42
  * ```
40
43
  */
41
44
  skipNullableAny?: boolean;
@@ -43,11 +46,14 @@ type MergeOptions = {
43
46
  * Skip nullable values when merging arrays?
44
47
  *
45
48
  * ```ts
46
- * merge([1, 2, 3], [null, null, 99]); // [1, 2, 99]
49
+ * merge([1, 2, 3], [null, null, 99]); // => [1, 2, 99]
47
50
  * ```
48
51
  */
49
52
  skipNullableInArrays?: boolean;
50
53
  };
54
+ /**
55
+ * A merger function for merging multiple arrays or objects into a single one
56
+ */
51
57
  type Merger = {
52
58
  /**
53
59
  * Merge multiple arrays or objects into a single one
@@ -72,7 +78,7 @@ declare namespace assign {
72
78
  /**
73
79
  * Create an assigner with predefined options
74
80
  *
75
- * Available as `initializeAssigner` and `assign.initialize`
81
+ * _Available as `initializeAssigner` and `assign.initialize`_
76
82
  *
77
83
  * @param options Assigning options
78
84
  * @returns Assigner function
@@ -81,7 +87,7 @@ declare function initializeAssigner(options?: AssignOptions): Assigner;
81
87
  /**
82
88
  * Create a merger with predefined options
83
89
  *
84
- * Available as `initializeMerger` and `merge.initialize`
90
+ * _Available as `initializeMerger` and `merge.initialize`_
85
91
  *
86
92
  * @param options Merging options
87
93
  * @returns Merger function
@@ -35,7 +35,7 @@ function getReplaceableObjects(value) {
35
35
  /**
36
36
  * Create an assigner with predefined options
37
37
  *
38
- * Available as `initializeAssigner` and `assign.initialize`
38
+ * _Available as `initializeAssigner` and `assign.initialize`_
39
39
  *
40
40
  * @param options Assigning options
41
41
  * @returns Assigner function
@@ -48,7 +48,7 @@ function initializeAssigner(options) {
48
48
  /**
49
49
  * Create a merger with predefined options
50
50
  *
51
- * Available as `initializeMerger` and `merge.initialize`
51
+ * _Available as `initializeMerger` and `merge.initialize`_
52
52
  *
53
53
  * @param options Merging options
54
54
  * @returns Merger function
@@ -3,6 +3,7 @@ import { PlainObject } from "../models.mjs";
3
3
  //#region src/value/omit.d.ts
4
4
  /**
5
5
  * Create a new object without the specified keys
6
+ *
6
7
  * @param value Original object
7
8
  * @param keys Keys to omit
8
9
  * @returns Partial object without the specified keys
@@ -2,6 +2,7 @@ import { partial } from "../internal/value/partial.mjs";
2
2
  //#region src/value/omit.ts
3
3
  /**
4
4
  * Create a new object without the specified keys
5
+ *
5
6
  * @param value Original object
6
7
  * @param keys Keys to omit
7
8
  * @returns Partial object without the specified keys
@@ -3,6 +3,7 @@ import { PlainObject } from "../models.mjs";
3
3
  //#region src/value/pick.d.ts
4
4
  /**
5
5
  * Create a new object with only the specified keys
6
+ *
6
7
  * @param value Original object
7
8
  * @param keys Keys to use
8
9
  * @returns Partial object with only the specified keys
@@ -2,6 +2,7 @@ import { partial } from "../internal/value/partial.mjs";
2
2
  //#region src/value/pick.ts
3
3
  /**
4
4
  * Create a new object with only the specified keys
5
+ *
5
6
  * @param value Original object
6
7
  * @param keys Keys to use
7
8
  * @returns Partial object with only the specified keys
@@ -7,6 +7,7 @@ import { PlainObject } from "../models.mjs";
7
7
  type Shaken<Value extends PlainObject> = { [Key in keyof Value]: Value[Key] extends undefined ? never : Value[Key] };
8
8
  /**
9
9
  * Shake an object, removing all keys with `undefined` values
10
+ *
10
11
  * @param value Object to shake
11
12
  * @returns Shaken object
12
13
  */
@@ -2,6 +2,7 @@ import { isNonPlainObject } from "../internal/is.mjs";
2
2
  //#region src/value/shake.ts
3
3
  /**
4
4
  * Shake an object, removing all keys with `undefined` values
5
+ *
5
6
  * @param value Object to shake
6
7
  * @returns Shaken object
7
8
  */
@@ -7,6 +7,7 @@ import { NestedKeys, NestedValue, PlainObject, Simplify, ToString } from "../mod
7
7
  type Smushed<Value extends PlainObject> = Simplify<{ [NestedKey in NestedKeys<Value>]: NestedValue<Value, ToString<NestedKey>> }>;
8
8
  /**
9
9
  * Smush an object into a flat object that uses dot notation keys
10
+ *
10
11
  * @param value Object to smush
11
12
  * @returns Smushed object with dot notation keys
12
13
  */
@@ -27,6 +27,7 @@ function flattenObject(value, depth, smushed, prefix) {
27
27
  }
28
28
  /**
29
29
  * Smush an object into a flat object that uses dot notation keys
30
+ *
30
31
  * @param value Object to smush
31
32
  * @returns Smushed object with dot notation keys
32
33
  */
@@ -18,7 +18,8 @@ type Transformer<Value extends PlainObject> = {
18
18
  /**
19
19
  * Initialize a transformer for an object with a transformer function
20
20
  *
21
- * Available as `initializeTransformer` and `transform.initialize`
21
+ * _Available as `initializeTransformer` and `transform.initialize`_
22
+ *
22
23
  * @param transform Transformer function
23
24
  * @returns Transformer
24
25
  */
@@ -26,13 +27,15 @@ declare function initializeTransformer<Value extends PlainObject>(transform: Tra
26
27
  /**
27
28
  * Initialize a transformer for an object with transformer functions
28
29
  *
29
- * Available as `initializeTransformer` and `transform.initialize`
30
+ * _Available as `initializeTransformer` and `transform.initialize`_
31
+ *
30
32
  * @param transformers Keyed transformer functions
31
33
  * @returns Transformer
32
34
  */
33
35
  declare function initializeTransformer<Value extends PlainObject>(transformers: TransformCallbacks<Value>): Transformer<Value>;
34
36
  /**
35
- * Transform and objects properties using a transformer functior
37
+ * Transform and objects properties using a transformer function
38
+ *
36
39
  * @param value Object to transform
37
40
  * @param transform Transformer function
38
41
  * @returns Transformed object
@@ -40,6 +43,7 @@ declare function initializeTransformer<Value extends PlainObject>(transformers:
40
43
  declare function transform<Value extends PlainObject, Key extends keyof Value>(value: Value, transform: TransformCallback<Value, Key>): Value;
41
44
  /**
42
45
  * Transform and objects properties using a transformer object
46
+ *
43
47
  * @param value Object to transform
44
48
  * @param transformers Keyed transformer functions
45
49
  * @returns Transformed object