@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
@@ -1,3 +1,4 @@
1
+ import {noop} from '../function';
1
2
  import {isPlainObject} from '../is';
2
3
  import type {ArrayOrPlainObject, GenericCallback, PlainObject} from '../models';
3
4
 
@@ -6,51 +7,180 @@ import type {ArrayOrPlainObject, GenericCallback, PlainObject} from '../models';
6
7
  /**
7
8
  * A frozen value with readonly properties _(going as deep as possible)_
8
9
  */
9
- export type Frozen<Value extends ArrayOrPlainObject> = {
10
- readonly [Key in keyof Value]: Value[Key] extends ArrayOrPlainObject
11
- ? Frozen<Value[Key]>
12
- : Value[Key];
13
- };
10
+ export type Frozen<Value> = Value extends unknown[]
11
+ ? Readonly<Value>
12
+ : Value extends PlainObject
13
+ ? {
14
+ readonly [Key in keyof Value]: Frozen<Value[Key]>;
15
+ }
16
+ : Value extends Map<infer Key, infer Value>
17
+ ? ReadonlyMap<Key, Frozen<Value>>
18
+ : Value extends Set<infer Item>
19
+ ? ReadonlySet<Frozen<Item>>
20
+ : Readonly<Value>;
14
21
 
15
22
  // #endregion
16
23
 
17
24
  // #region Functions
18
25
 
26
+ function fakeDelete(): boolean {
27
+ return false;
28
+ }
29
+
19
30
  /**
20
- * Freeze an array and all its indices recursively
31
+ * Freeze an array and its indiced values, but not any nested values
32
+ *
33
+ * _Available as `flatFreeze` and `freeze.flat`_
34
+ *
35
+ * @param array Array to freeze
36
+ * @returns Frozen array
37
+ */
38
+ export function flatFreeze<Item>(array: Item[]): ReadonlyArray<Item>;
39
+
40
+ /**
41
+ * Freeze a map and its values, but not any nested values
42
+ *
43
+ * _Available as `flatFreeze` and `freeze.flat`_
44
+ *
45
+ * @param map Map to freeze
46
+ * @returns Frozen map
47
+ */
48
+ export function flatFreeze<Key, Value>(map: Map<Key, Value>): ReadonlyMap<Key, Value>;
49
+
50
+ /**
51
+ * Freeze an object and its properties, but not any nested values
52
+ *
53
+ * _Available as `flatFreeze` and `freeze.flat`_
54
+ *
55
+ * @param object Object to freeze
56
+ * @returns Frozen object
57
+ */
58
+ export function flatFreeze<Value extends PlainObject>(object: Value): Readonly<Value>;
59
+
60
+ /**
61
+ * Freeze a set and its values, but not any nested values
62
+ *
63
+ * _Available as `flatFreeze` and `freeze.flat`_
64
+ *
65
+ * @param set Set to freeze
66
+ * @returns Frozen set
67
+ */
68
+ export function flatFreeze<Item>(set: Set<Item>): ReadonlySet<Item>;
69
+
70
+ /**
71
+ * Freeze any value, if possible
72
+ *
73
+ * _(Only arrays, maps, plain objects, and sets are freezable)_
74
+ *
75
+ * _Available as `flatFreeze` and `freeze.flat`_
76
+ *
77
+ * @param value Value to freeze
78
+ * @returns Frozen value
79
+ */
80
+ export function flatFreeze<Value>(value: Value): Value;
81
+
82
+ export function flatFreeze(value: unknown): unknown {
83
+ return freezeValue(value, new WeakSet(), true);
84
+ }
85
+
86
+ /**
87
+ * Freeze an array and its values _(but not any nested values)_, preventing modifications
88
+ *
89
+ * @param array Array to freeze
90
+ * @param flat Freeze _only_ the array, not any nested values
91
+ * @returns Frozen array
92
+ */
93
+ export function freeze<Item>(array: Item[], flat: true): ReadonlyArray<Item>;
94
+
95
+ /**
96
+ * Freeze a map and its values _(but not any nested values)_, preventing modifications
97
+ *
98
+ * @param map Map to freeze
99
+ * @param flat Freeze _only_ the map, not any nested values
100
+ * @returns Frozen map
101
+ */
102
+ export function freeze<Key, Value>(map: Map<Key, Value>, flat: true): ReadonlyMap<Key, Value>;
103
+
104
+ /**
105
+ * Freeze an object and its properties _(but not any nested values)_, preventing modifications
106
+ *
107
+ * @param object Object to freeze
108
+ * @param flat Freeze _only_ the object, not any nested values
109
+ * @returns Frozen object
110
+ */
111
+ export function freeze<Value extends PlainObject>(object: Value, flat: true): Readonly<Value>;
112
+
113
+ /**
114
+ * Freeze a set and its values _(but not any nested values)_, preventing modifications
115
+ *
116
+ * @param set Set to freeze
117
+ * @param flat Freeze _only_ the set, not any nested values
118
+ * @returns Frozen set
119
+ */
120
+ export function freeze<Item>(set: Set<Item>, flat: true): ReadonlySet<Item>;
121
+
122
+ /**
123
+ * Freeze an array and its values recursively, preventing modifications
124
+ *
125
+ * _(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)_
126
+ *
21
127
  * @param array Array to freeze
22
128
  * @returns Frozen array
23
129
  */
24
130
  export function freeze<Item>(array: Item[]): Frozen<Item[]>;
25
131
 
26
132
  /**
27
- * Freeze a function
28
- * @param fn Function to freeze
29
- * @returns Frozen function
133
+ * Freeze a map and its values recursively, preventing modifications
134
+ *
135
+ * _(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)_
136
+ *
137
+ * @param map Map to freeze
138
+ * @returns Frozen map
30
139
  */
31
- export function freeze<Fn extends GenericCallback>(fn: Fn): Readonly<Fn>;
140
+ export function freeze<Key, Value>(map: Map<Key, Value>): Frozen<Map<Key, Value>>;
32
141
 
33
142
  /**
34
143
  * Freeze an object and all its properties recursively
144
+ *
145
+ * _(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)_
146
+ *
35
147
  * @param object Object to freeze
36
148
  * @returns Frozen object
37
149
  */
38
150
  export function freeze<Value extends PlainObject>(object: Value): Frozen<Value>;
39
151
 
152
+ /**
153
+ * Freeze a set and its values recursively
154
+ *
155
+ * _(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)_
156
+ *
157
+ * @param set Set to freeze
158
+ * @returns Frozen set
159
+ */
160
+ export function freeze<Item>(set: Set<Item>): Frozen<Set<Item>>;
161
+
40
162
  /**
41
163
  * Freeze any value, if possible
42
164
  *
43
- * _(Only arrays, functions, and plain objects are freezable)_
165
+ * _(Only arrays, maps, plain objects, and sets are freezable)_
166
+ *
44
167
  * @param value Value to freeze
45
168
  * @returns Frozen value
46
169
  */
47
170
  export function freeze<Value>(value: Value): Value;
48
171
 
49
- export function freeze(value: unknown): unknown {
50
- return freezeValue(value, new WeakSet());
172
+ export function freeze(value: unknown, flat?: unknown): unknown {
173
+ return freezeValue(value, new WeakSet(), flat === true);
51
174
  }
52
175
 
53
- function freezeArray(array: unknown[], references: WeakSet<any>): Frozen<unknown[]> {
176
+ freeze.flat = flatFreeze;
177
+ freeze.is = isFrozen;
178
+
179
+ function freezeArray(array: unknown[], references: WeakSet<any>, flat: boolean): Frozen<unknown[]> {
180
+ if (flat) {
181
+ return Object.freeze(array) as Frozen<unknown[]>;
182
+ }
183
+
54
184
  references.add(array);
55
185
 
56
186
  const {length} = array;
@@ -59,20 +189,50 @@ function freezeArray(array: unknown[], references: WeakSet<any>): Frozen<unknown
59
189
  const value = array[index];
60
190
 
61
191
  if (!references.has(value)) {
62
- array[index] = freezeValue(array[index], references);
192
+ array[index] = freezeValue(array[index], references, false);
63
193
  }
64
194
  }
65
195
 
66
196
  return Object.freeze(array) as Frozen<unknown[]>;
67
197
  }
68
198
 
69
- function freezeFunction(fn: Function, references: WeakSet<any>): Readonly<Function> {
70
- references.add(fn);
199
+ function freezeMap(
200
+ map: Map<unknown, unknown>,
201
+ references: WeakSet<any>,
202
+ flat: boolean,
203
+ ): ReadonlyMap<unknown, unknown> {
204
+ frozenValues.add(map);
205
+
206
+ map.clear = noop;
207
+ map.delete = fakeDelete;
208
+ map.set = () => map;
209
+
210
+ if (flat) {
211
+ return map as ReadonlyMap<unknown, unknown>;
212
+ }
213
+
214
+ references.add(map);
71
215
 
72
- return Object.freeze(fn);
216
+ const entries = map.entries();
217
+
218
+ for (const [key, value] of entries) {
219
+ if (!references.has(value)) {
220
+ map.set(key, freezeValue(value, references, false));
221
+ }
222
+ }
223
+
224
+ return map as ReadonlyMap<unknown, unknown>;
73
225
  }
74
226
 
75
- function freezeObject(object: PlainObject, references: WeakSet<any>): Frozen<PlainObject> {
227
+ function freezeObject(
228
+ object: PlainObject,
229
+ references: WeakSet<any>,
230
+ flat: boolean,
231
+ ): Frozen<PlainObject> {
232
+ if (flat) {
233
+ return Object.freeze(object) as Frozen<PlainObject>;
234
+ }
235
+
76
236
  references.add(object);
77
237
 
78
238
  const keys = Object.keys(object);
@@ -82,27 +242,81 @@ function freezeObject(object: PlainObject, references: WeakSet<any>): Frozen<Pla
82
242
  const key = keys[index];
83
243
 
84
244
  if (!references.has(object[key])) {
85
- object[key] = freezeValue(object[key], references);
245
+ object[key] = freezeValue(object[key], references, false);
86
246
  }
87
247
  }
88
248
 
89
249
  return Object.freeze(object) as Frozen<PlainObject>;
90
250
  }
91
251
 
92
- function freezeValue(value: unknown, references: WeakSet<any>): unknown {
252
+ function freezeSet(
253
+ set: Set<unknown>,
254
+ references: WeakSet<any>,
255
+ flat: boolean,
256
+ ): ReadonlySet<unknown> {
257
+ frozenValues.add(set);
258
+
259
+ set.clear = noop;
260
+ set.delete = fakeDelete;
261
+ set.add = () => set;
262
+
263
+ if (flat) {
264
+ return set as ReadonlySet<unknown>;
265
+ }
266
+
267
+ references.add(set);
268
+
269
+ const values = set.values();
270
+
271
+ for (const value of values) {
272
+ if (!references.has(value)) {
273
+ set.add(freezeValue(value, references, false));
274
+ }
275
+ }
276
+
277
+ return set as ReadonlySet<unknown>;
278
+ }
279
+
280
+ function freezeValue(value: unknown, references: WeakSet<any>, flat: boolean): unknown {
93
281
  switch (true) {
94
- case typeof value === 'function':
95
- return freezeFunction(value, references);
282
+ case isFrozen(value):
283
+ return value;
284
+
285
+ case value instanceof Map:
286
+ return freezeMap(value, references, flat);
287
+
288
+ case value instanceof Set:
289
+ return freezeSet(value, references, flat);
96
290
 
97
291
  case Array.isArray(value):
98
- return freezeArray(value, references);
292
+ return freezeArray(value, references, flat);
99
293
 
100
294
  case isPlainObject(value):
101
- return freezeObject(value, references);
295
+ return freezeObject(value, references, flat);
102
296
 
103
297
  default:
104
298
  return value;
105
299
  }
106
300
  }
107
301
 
302
+ /**
303
+ * Is the value frozen?
304
+ *
305
+ * @param value Value to check
306
+ * @returns `true` if the value is frozen, otherwise `false`
307
+ */
308
+ export function isFrozen(value: unknown): boolean {
309
+ if (value instanceof Map || value instanceof Set) {
310
+ return frozenValues.has(value);
311
+ }
312
+
313
+ return typeof value === 'object' && value !== null && Object.isFrozen(value);
314
+ }
315
+
316
+ // #endregion
317
+
318
+ // #region Variables
319
+
320
+ const frozenValues = new WeakSet();
321
+
108
322
  // #endregion
@@ -1,4 +1,3 @@
1
- export {freeze, type Frozen} from './freeze';
2
1
  export {omit} from './omit';
3
2
  export {pick} from './pick';
4
3
  export {shake, type Shaken} from './shake';
@@ -8,6 +8,9 @@ import type {ArrayOrPlainObject, NestedPartial, PlainObject, UnionToIntersection
8
8
  */
9
9
  export type AssignOptions = Omit<MergeOptions, 'assignValues'>;
10
10
 
11
+ /**
12
+ * An assigner function for assigning values from one or more objects to the first one
13
+ */
11
14
  export type Assigner = {
12
15
  /**
13
16
  * Assign values from one or more objects to the first one
@@ -34,7 +37,7 @@ export type MergeOptions = {
34
37
  * Key _(or key epxressions)_ for values that should be replaced
35
38
  *
36
39
  * ```ts
37
- * merge([{items: [1, 2, 3]}, {items: [99]}]); // {items: [99]}
40
+ * merge([{items: [1, 2, 3]}, {items: [99]}]); // => {items: [99]}
38
41
  * ```
39
42
  */
40
43
  replaceableObjects?: string | RegExp | Array<string | RegExp>;
@@ -42,7 +45,7 @@ export type MergeOptions = {
42
45
  * Skip nullable values when merging objects?
43
46
  *
44
47
  * ```ts
45
- * merge({a: 1, b: 2}, {b: null, c: 3}, {d: null}); // {a: 1, b: 2, c: 3}
48
+ * merge({a: 1, b: 2}, {b: null, c: 3}, {d: null}); // => {a: 1, b: 2, c: 3}
46
49
  * ```
47
50
  */
48
51
  skipNullableAny?: boolean;
@@ -50,12 +53,15 @@ export type MergeOptions = {
50
53
  * Skip nullable values when merging arrays?
51
54
  *
52
55
  * ```ts
53
- * merge([1, 2, 3], [null, null, 99]); // [1, 2, 99]
56
+ * merge([1, 2, 3], [null, null, 99]); // => [1, 2, 99]
54
57
  * ```
55
58
  */
56
59
  skipNullableInArrays?: boolean;
57
60
  };
58
61
 
62
+ /**
63
+ * A merger function for merging multiple arrays or objects into a single one
64
+ */
59
65
  export type Merger = {
60
66
  /**
61
67
  * Merge multiple arrays or objects into a single one
@@ -138,7 +144,7 @@ function getReplaceableObjects(value: unknown): ReplaceableObjectsCallback | und
138
144
  /**
139
145
  * Create an assigner with predefined options
140
146
  *
141
- * Available as `initializeAssigner` and `assign.initialize`
147
+ * _Available as `initializeAssigner` and `assign.initialize`_
142
148
  *
143
149
  * @param options Assigning options
144
150
  * @returns Assigner function
@@ -155,7 +161,7 @@ export function initializeAssigner(options?: AssignOptions): Assigner {
155
161
  /**
156
162
  * Create a merger with predefined options
157
163
  *
158
- * Available as `initializeMerger` and `merge.initialize`
164
+ * _Available as `initializeMerger` and `merge.initialize`_
159
165
  *
160
166
  * @param options Merging options
161
167
  * @returns Merger function
package/src/value/omit.ts CHANGED
@@ -5,6 +5,7 @@ import type {PlainObject} from '../models';
5
5
 
6
6
  /**
7
7
  * Create a new object without the specified keys
8
+ *
8
9
  * @param value Original object
9
10
  * @param keys Keys to omit
10
11
  * @returns Partial object without the specified keys
package/src/value/pick.ts CHANGED
@@ -5,6 +5,7 @@ import type {PlainObject} from '../models';
5
5
 
6
6
  /**
7
7
  * Create a new object with only the specified keys
8
+ *
8
9
  * @param value Original object
9
10
  * @param keys Keys to use
10
11
  * @returns Partial object with only the specified keys
@@ -16,6 +16,7 @@ export type Shaken<Value extends PlainObject> = {
16
16
 
17
17
  /**
18
18
  * Shake an object, removing all keys with `undefined` values
19
+ *
19
20
  * @param value Object to shake
20
21
  * @returns Shaken object
21
22
  */
@@ -70,6 +70,7 @@ function flattenObject(
70
70
 
71
71
  /**
72
72
  * Smush an object into a flat object that uses dot notation keys
73
+ *
73
74
  * @param value Object to smush
74
75
  * @returns Smushed object with dot notation keys
75
76
  */
@@ -62,7 +62,8 @@ function getTransformer<Value extends PlainObject, Key extends keyof Value>(
62
62
  /**
63
63
  * Initialize a transformer for an object with a transformer function
64
64
  *
65
- * Available as `initializeTransformer` and `transform.initialize`
65
+ * _Available as `initializeTransformer` and `transform.initialize`_
66
+ *
66
67
  * @param transform Transformer function
67
68
  * @returns Transformer
68
69
  */
@@ -73,7 +74,8 @@ export function initializeTransformer<Value extends PlainObject>(
73
74
  /**
74
75
  * Initialize a transformer for an object with transformer functions
75
76
  *
76
- * Available as `initializeTransformer` and `transform.initialize`
77
+ * _Available as `initializeTransformer` and `transform.initialize`_
78
+ *
77
79
  * @param transformers Keyed transformer functions
78
80
  * @returns Transformer
79
81
  */
@@ -90,7 +92,8 @@ export function initializeTransformer<Value extends PlainObject>(
90
92
  }
91
93
 
92
94
  /**
93
- * Transform and objects properties using a transformer functior
95
+ * Transform and objects properties using a transformer function
96
+ *
94
97
  * @param value Object to transform
95
98
  * @param transform Transformer function
96
99
  * @returns Transformed object
@@ -102,6 +105,7 @@ export function transform<Value extends PlainObject, Key extends keyof Value>(
102
105
 
103
106
  /**
104
107
  * Transform and objects properties using a transformer object
108
+ *
105
109
  * @param value Object to transform
106
110
  * @param transformers Keyed transformer functions
107
111
  * @returns Transformed object
@@ -52,6 +52,7 @@ function getKeys(value: PlainObject): OrderedKey[] {
52
52
 
53
53
  /**
54
54
  * Unsmush a smushed object _(turning dot notation keys into nested keys)_
55
+ *
55
56
  * @param value Object to unsmush
56
57
  * @returns Unsmushed object with nested keys
57
58
  */