@oscarpalmer/atoms 0.193.0 → 0.194.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.
- package/dist/array/difference.mjs +2 -2
- package/dist/array/intersection.mjs +2 -2
- package/dist/array/match.mjs +13 -13
- package/dist/array/slice.mjs +5 -5
- package/dist/array/sort.d.mts +5 -1
- package/dist/array/sort.mjs +4 -2
- package/dist/array/union.mjs +2 -2
- package/dist/beacon.d.mts +8 -1
- package/dist/beacon.mjs +52 -60
- package/dist/color/constants.d.mts +1 -1
- package/dist/color/constants.mjs +3 -5
- package/dist/color/instance.mjs +34 -41
- package/dist/color/misc/format.d.mts +3 -2
- package/dist/color/misc/format.mjs +4 -1
- package/dist/color/misc/is.d.mts +9 -1
- package/dist/color/misc/is.mjs +11 -1
- package/dist/color/misc/state.d.mts +6 -6
- package/dist/color/misc/state.mjs +11 -14
- package/dist/color/models.d.mts +23 -68
- package/dist/function/assert.mjs +2 -2
- package/dist/function/limit.d.mts +0 -6
- package/dist/function/limit.mjs +2 -2
- package/dist/function/memoize.mjs +19 -32
- package/dist/function/once.d.mts +0 -3
- package/dist/function/once.mjs +16 -13
- package/dist/function/retry.d.mts +1 -24
- package/dist/function/retry.mjs +1 -1
- package/dist/function/work.mjs +13 -11
- package/dist/herald.d.mts +30 -31
- package/dist/herald.mjs +74 -56
- package/dist/index.d.mts +100 -185
- package/dist/index.mjs +680 -702
- package/dist/internal/abort.d.mts +10 -0
- package/dist/internal/abort.mjs +14 -0
- package/dist/internal/array/chunk.mjs +2 -2
- package/dist/internal/array/find.mjs +2 -2
- package/dist/internal/array/sets.d.mts +4 -4
- package/dist/internal/array/sets.mjs +7 -7
- package/dist/internal/function/timer.mjs +19 -15
- package/dist/internal/number.mjs +7 -7
- package/dist/internal/result.mjs +3 -3
- package/dist/internal/sized.mjs +4 -4
- package/dist/internal/string.mjs +4 -4
- package/dist/internal/subscription.d.mts +24 -8
- package/dist/internal/subscription.mjs +49 -36
- package/dist/internal/value/equal.mjs +6 -6
- package/dist/internal/value/misc.mjs +14 -14
- package/dist/internal/value/set.mjs +2 -2
- package/dist/logger.mjs +15 -39
- package/dist/promise/constants.d.mts +17 -0
- package/dist/promise/constants.mjs +14 -0
- package/dist/promise/delay.mjs +7 -10
- package/dist/promise/helpers.mjs +1 -1
- package/dist/promise/index.mjs +14 -17
- package/dist/promise/misc.d.mts +2 -1
- package/dist/promise/misc.mjs +8 -7
- package/dist/promise/models.d.mts +4 -16
- package/dist/promise/models.mjs +4 -13
- package/dist/promise/timed.mjs +9 -10
- package/dist/query.mjs +15 -15
- package/dist/queue.mjs +103 -116
- package/dist/random.mjs +7 -7
- package/dist/result/index.d.mts +0 -3
- package/dist/result/index.mjs +1 -1
- package/dist/result/match.d.mts +0 -3
- package/dist/result/match.mjs +4 -4
- package/dist/result/misc.mjs +2 -2
- package/dist/result/work/flow.d.mts +0 -3
- package/dist/result/work/flow.mjs +5 -5
- package/dist/result/work/pipe.d.mts +0 -3
- package/dist/result/work/pipe.mjs +3 -3
- package/dist/string/case.mjs +20 -20
- package/dist/string/fuzzy.mjs +23 -18
- package/dist/string/index.mjs +7 -7
- package/dist/string/normalize.mjs +14 -14
- package/dist/string/template.mjs +2 -2
- package/dist/value/clone.mjs +10 -10
- package/dist/value/smush.mjs +2 -2
- package/package.json +13 -5
- package/src/array/difference.ts +0 -73
- package/src/array/exists.ts +0 -93
- package/src/array/filter.ts +0 -182
- package/src/array/find.ts +0 -183
- package/src/array/first.ts +0 -196
- package/src/array/flatten.ts +0 -20
- package/src/array/from.ts +0 -129
- package/src/array/get.ts +0 -131
- package/src/array/group-by.ts +0 -369
- package/src/array/index.ts +0 -26
- package/src/array/insert.ts +0 -52
- package/src/array/intersection.ts +0 -72
- package/src/array/last.ts +0 -194
- package/src/array/match.ts +0 -436
- package/src/array/move.ts +0 -315
- package/src/array/partition.ts +0 -91
- package/src/array/push.ts +0 -23
- package/src/array/reverse.ts +0 -33
- package/src/array/select.ts +0 -260
- package/src/array/single.ts +0 -93
- package/src/array/slice.ts +0 -335
- package/src/array/sort.ts +0 -607
- package/src/array/splice.ts +0 -106
- package/src/array/swap.ts +0 -322
- package/src/array/to-map.ts +0 -371
- package/src/array/to-record.ts +0 -351
- package/src/array/to-set.ts +0 -80
- package/src/array/toggle.ts +0 -79
- package/src/array/union.ts +0 -72
- package/src/array/unique.ts +0 -67
- package/src/array/update.ts +0 -75
- package/src/beacon.ts +0 -378
- package/src/color/constants.ts +0 -137
- package/src/color/index.ts +0 -83
- package/src/color/instance.ts +0 -162
- package/src/color/misc/alpha.ts +0 -56
- package/src/color/misc/format.ts +0 -29
- package/src/color/misc/get.ts +0 -210
- package/src/color/misc/is.ts +0 -221
- package/src/color/misc/state.ts +0 -243
- package/src/color/models.ts +0 -389
- package/src/color/space/hex.ts +0 -184
- package/src/color/space/hsl.ts +0 -174
- package/src/color/space/hwb.ts +0 -153
- package/src/color/space/rgb.ts +0 -240
- package/src/function/assert.ts +0 -174
- package/src/function/index.ts +0 -2
- package/src/function/limit.ts +0 -83
- package/src/function/memoize.ts +0 -202
- package/src/function/once.ts +0 -200
- package/src/function/retry.ts +0 -175
- package/src/function/work.ts +0 -1007
- package/src/herald.ts +0 -216
- package/src/index.ts +0 -68
- package/src/internal/array/callbacks.ts +0 -46
- package/src/internal/array/chunk.ts +0 -51
- package/src/internal/array/compact.ts +0 -56
- package/src/internal/array/find.ts +0 -200
- package/src/internal/array/group.ts +0 -42
- package/src/internal/array/index-of.ts +0 -182
- package/src/internal/array/insert.ts +0 -80
- package/src/internal/array/overlap.ts +0 -35
- package/src/internal/array/sets.ts +0 -74
- package/src/internal/array/shuffle.ts +0 -33
- package/src/internal/array/update.ts +0 -52
- package/src/internal/function/misc.ts +0 -8
- package/src/internal/function/timer.ts +0 -168
- package/src/internal/is.ts +0 -244
- package/src/internal/math/aggregate.ts +0 -164
- package/src/internal/math/misc.ts +0 -28
- package/src/internal/number.ts +0 -129
- package/src/internal/random.ts +0 -49
- package/src/internal/result.ts +0 -92
- package/src/internal/sized.ts +0 -25
- package/src/internal/string.ts +0 -128
- package/src/internal/subscription.ts +0 -264
- package/src/internal/value/compare.ts +0 -170
- package/src/internal/value/equal.ts +0 -465
- package/src/internal/value/get.ts +0 -57
- package/src/internal/value/handlers.ts +0 -95
- package/src/internal/value/has.ts +0 -118
- package/src/internal/value/misc.ts +0 -125
- package/src/internal/value/partial.ts +0 -46
- package/src/internal/value/set.ts +0 -132
- package/src/is.ts +0 -182
- package/src/logger.ts +0 -230
- package/src/math.ts +0 -281
- package/src/models.ts +0 -286
- package/src/number.ts +0 -1
- package/src/promise/delay.ts +0 -62
- package/src/promise/helpers.ts +0 -96
- package/src/promise/index.ts +0 -300
- package/src/promise/misc.ts +0 -96
- package/src/promise/models.ts +0 -195
- package/src/promise/timed.ts +0 -91
- package/src/query.ts +0 -147
- package/src/queue.ts +0 -814
- package/src/random.ts +0 -125
- package/src/result/index.ts +0 -105
- package/src/result/match.ts +0 -124
- package/src/result/misc.ts +0 -129
- package/src/result/models.ts +0 -83
- package/src/result/work/flow.ts +0 -488
- package/src/result/work/pipe.ts +0 -496
- package/src/sized/map.ts +0 -110
- package/src/sized/set.ts +0 -107
- package/src/string/case.ts +0 -236
- package/src/string/fuzzy.ts +0 -444
- package/src/string/index.ts +0 -199
- package/src/string/match.ts +0 -80
- package/src/string/normalize.ts +0 -205
- package/src/string/template.ts +0 -161
- package/src/value/clone.ts +0 -319
- package/src/value/collection.ts +0 -63
- package/src/value/diff.ts +0 -232
- package/src/value/freeze.ts +0 -322
- package/src/value/handle.ts +0 -3
- package/src/value/index.ts +0 -5
- package/src/value/merge.ts +0 -278
- package/src/value/omit.ts +0 -20
- package/src/value/pick.ts +0 -20
- package/src/value/shake.ts +0 -45
- package/src/value/smush.ts +0 -89
- package/src/value/transform.ts +0 -153
- package/src/value/unsmush.ts +0 -84
package/src/value/freeze.ts
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import {noop} from '../function';
|
|
2
|
-
import {isPlainObject} from '../internal/is';
|
|
3
|
-
import type {PlainObject} from '../models';
|
|
4
|
-
|
|
5
|
-
// #region Types
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A frozen value with readonly properties _(going as deep as possible)_
|
|
9
|
-
*/
|
|
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>;
|
|
21
|
-
|
|
22
|
-
// #endregion
|
|
23
|
-
|
|
24
|
-
// #region Functions
|
|
25
|
-
|
|
26
|
-
function fakeDelete(): boolean {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
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
|
-
*
|
|
127
|
-
* @param array Array to freeze
|
|
128
|
-
* @returns Frozen array
|
|
129
|
-
*/
|
|
130
|
-
export function freeze<Item>(array: Item[]): Frozen<Item[]>;
|
|
131
|
-
|
|
132
|
-
/**
|
|
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
|
|
139
|
-
*/
|
|
140
|
-
export function freeze<Key, Value>(map: Map<Key, Value>): Frozen<Map<Key, Value>>;
|
|
141
|
-
|
|
142
|
-
/**
|
|
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
|
-
*
|
|
147
|
-
* @param object Object to freeze
|
|
148
|
-
* @returns Frozen object
|
|
149
|
-
*/
|
|
150
|
-
export function freeze<Value extends PlainObject>(object: Value): Frozen<Value>;
|
|
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
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Freeze any value, if possible
|
|
164
|
-
*
|
|
165
|
-
* _(Only arrays, maps, plain objects, and sets are freezable)_
|
|
166
|
-
*
|
|
167
|
-
* @param value Value to freeze
|
|
168
|
-
* @returns Frozen value
|
|
169
|
-
*/
|
|
170
|
-
export function freeze<Value>(value: Value): Value;
|
|
171
|
-
|
|
172
|
-
export function freeze(value: unknown, flat?: unknown): unknown {
|
|
173
|
-
return freezeValue(value, new WeakSet(), flat === true);
|
|
174
|
-
}
|
|
175
|
-
|
|
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
|
-
|
|
184
|
-
references.add(array);
|
|
185
|
-
|
|
186
|
-
const {length} = array;
|
|
187
|
-
|
|
188
|
-
for (let index = 0; index < length; index += 1) {
|
|
189
|
-
const value = array[index];
|
|
190
|
-
|
|
191
|
-
if (!references.has(value)) {
|
|
192
|
-
array[index] = freezeValue(array[index], references, false);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return Object.freeze(array) as Frozen<unknown[]>;
|
|
197
|
-
}
|
|
198
|
-
|
|
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);
|
|
215
|
-
|
|
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>;
|
|
225
|
-
}
|
|
226
|
-
|
|
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
|
-
|
|
236
|
-
references.add(object);
|
|
237
|
-
|
|
238
|
-
const keys = Object.keys(object);
|
|
239
|
-
const {length} = keys;
|
|
240
|
-
|
|
241
|
-
for (let index = 0; index < length; index += 1) {
|
|
242
|
-
const key = keys[index];
|
|
243
|
-
|
|
244
|
-
if (!references.has(object[key])) {
|
|
245
|
-
object[key] = freezeValue(object[key], references, false);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return Object.freeze(object) as Frozen<PlainObject>;
|
|
250
|
-
}
|
|
251
|
-
|
|
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 {
|
|
281
|
-
switch (true) {
|
|
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);
|
|
290
|
-
|
|
291
|
-
case Array.isArray(value):
|
|
292
|
-
return freezeArray(value, references, flat);
|
|
293
|
-
|
|
294
|
-
case isPlainObject(value):
|
|
295
|
-
return freezeObject(value, references, flat);
|
|
296
|
-
|
|
297
|
-
default:
|
|
298
|
-
return value;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
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
|
-
|
|
322
|
-
// #endregion
|
package/src/value/handle.ts
DELETED
package/src/value/index.ts
DELETED
package/src/value/merge.ts
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import {isArrayOrPlainObject} from '../internal/is';
|
|
2
|
-
import type {ArrayOrPlainObject, NestedPartial, PlainObject, UnionToIntersection} from '../models';
|
|
3
|
-
|
|
4
|
-
// #region Types
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Options for assigning values
|
|
8
|
-
*/
|
|
9
|
-
export type AssignOptions = Omit<MergeOptions, 'assignValues'>;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* An assigner function for assigning values from one or more objects to the first one
|
|
13
|
-
*/
|
|
14
|
-
export type Assigner = {
|
|
15
|
-
/**
|
|
16
|
-
* Assign values from one or more objects to the first one
|
|
17
|
-
*
|
|
18
|
-
* @param to Value to assign to
|
|
19
|
-
* @param from Values to assign
|
|
20
|
-
* @returns Assigned value
|
|
21
|
-
*/
|
|
22
|
-
<To extends PlainObject, From extends PlainObject[]>(
|
|
23
|
-
to: To,
|
|
24
|
-
from: [...From],
|
|
25
|
-
): To & UnionToIntersection<From[number]>;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Options for merging values
|
|
30
|
-
*/
|
|
31
|
-
export type MergeOptions = {
|
|
32
|
-
/**
|
|
33
|
-
* Assign values to the first array or object instead of creating a new one?
|
|
34
|
-
*/
|
|
35
|
-
assignValues?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Key _(or key epxressions)_ for values that should be replaced
|
|
38
|
-
*
|
|
39
|
-
* ```ts
|
|
40
|
-
* merge([{items: [1, 2, 3]}, {items: [99]}]); // => {items: [99]}
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
replaceableObjects?: string | RegExp | Array<string | RegExp>;
|
|
44
|
-
/**
|
|
45
|
-
* Skip nullable values when merging objects?
|
|
46
|
-
*
|
|
47
|
-
* ```ts
|
|
48
|
-
* merge({a: 1, b: 2}, {b: null, c: 3}, {d: null}); // => {a: 1, b: 2, c: 3}
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
skipNullableAny?: boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Skip nullable values when merging arrays?
|
|
54
|
-
*
|
|
55
|
-
* ```ts
|
|
56
|
-
* merge([1, 2, 3], [null, null, 99]); // => [1, 2, 99]
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
skipNullableInArrays?: boolean;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* A merger function for merging multiple arrays or objects into a single one
|
|
64
|
-
*/
|
|
65
|
-
export type Merger = {
|
|
66
|
-
/**
|
|
67
|
-
* Merge multiple arrays or objects into a single one
|
|
68
|
-
*
|
|
69
|
-
* @param values Values to merge
|
|
70
|
-
* @returns Merged value
|
|
71
|
-
*/
|
|
72
|
-
<Values extends ArrayOrPlainObject[]>(
|
|
73
|
-
values: NestedPartial<Values[number]>[],
|
|
74
|
-
): UnionToIntersection<Values[number]>;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
type Options = {
|
|
78
|
-
assignValues: boolean;
|
|
79
|
-
replaceableObjects: ReplaceableObjectsCallback | undefined;
|
|
80
|
-
skipNullableAny: boolean;
|
|
81
|
-
skipNullableInArrays: boolean;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
type ReplaceableObjectsCallback = (name: string) => boolean;
|
|
85
|
-
|
|
86
|
-
// #endregion
|
|
87
|
-
|
|
88
|
-
// #region Functions
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Assign values from one or more objects to the first one
|
|
92
|
-
*
|
|
93
|
-
* @param to Value to assign to
|
|
94
|
-
* @param from Values to assign
|
|
95
|
-
* @param options Assigning options
|
|
96
|
-
* @returns Assigned value
|
|
97
|
-
*/
|
|
98
|
-
export function assign<To extends PlainObject, From extends PlainObject[]>(
|
|
99
|
-
to: To,
|
|
100
|
-
from: [...From],
|
|
101
|
-
options?: AssignOptions,
|
|
102
|
-
): To & UnionToIntersection<From[number]> {
|
|
103
|
-
const actual = getMergeOptions(options);
|
|
104
|
-
|
|
105
|
-
actual.assignValues = true;
|
|
106
|
-
|
|
107
|
-
return mergeValues([to, ...from], actual) as To & UnionToIntersection<From[number]>;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
assign.initialize = initializeAssigner;
|
|
111
|
-
|
|
112
|
-
function getMergeOptions(options?: MergeOptions): Options {
|
|
113
|
-
const actual: Options = {
|
|
114
|
-
assignValues: false,
|
|
115
|
-
replaceableObjects: undefined,
|
|
116
|
-
skipNullableAny: false,
|
|
117
|
-
skipNullableInArrays: false,
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
if (typeof options !== 'object' || options == null) {
|
|
121
|
-
return actual;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
actual.replaceableObjects = getReplaceableObjects(options.replaceableObjects);
|
|
125
|
-
|
|
126
|
-
actual.assignValues = options.assignValues === true;
|
|
127
|
-
actual.skipNullableAny = options.skipNullableAny === true;
|
|
128
|
-
actual.skipNullableInArrays = options.skipNullableInArrays === true;
|
|
129
|
-
|
|
130
|
-
return actual;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function getReplaceableObjects(value: unknown): ReplaceableObjectsCallback | undefined {
|
|
134
|
-
const items = (Array.isArray(value) ? value : [value]).filter(
|
|
135
|
-
item => typeof item === 'string' || item instanceof RegExp,
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
if (items.length > 0) {
|
|
139
|
-
return (name: string) =>
|
|
140
|
-
items.some(item => (typeof item === 'string' ? item === name : item.test(name)));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Create an assigner with predefined options
|
|
146
|
-
*
|
|
147
|
-
* _Available as `initializeAssigner` and `assign.initialize`_
|
|
148
|
-
*
|
|
149
|
-
* @param options Assigning options
|
|
150
|
-
* @returns Assigner function
|
|
151
|
-
*/
|
|
152
|
-
export function initializeAssigner(options?: AssignOptions): Assigner {
|
|
153
|
-
const actual = getMergeOptions(options);
|
|
154
|
-
|
|
155
|
-
actual.assignValues = true;
|
|
156
|
-
|
|
157
|
-
return ((to: PlainObject, from: PlainObject[]): PlainObject =>
|
|
158
|
-
mergeValues([to, ...from], actual) as PlainObject) as Assigner;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Create a merger with predefined options
|
|
163
|
-
*
|
|
164
|
-
* _Available as `initializeMerger` and `merge.initialize`_
|
|
165
|
-
*
|
|
166
|
-
* @param options Merging options
|
|
167
|
-
* @returns Merger function
|
|
168
|
-
*/
|
|
169
|
-
export function initializeMerger(options?: MergeOptions): Merger {
|
|
170
|
-
const actual = getMergeOptions(options);
|
|
171
|
-
|
|
172
|
-
return ((values: NestedPartial<ArrayOrPlainObject>[]): ArrayOrPlainObject =>
|
|
173
|
-
mergeValues(values, actual)) as Merger;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Merge multiple arrays or objects into a single one
|
|
178
|
-
*
|
|
179
|
-
* @param values Values to merge
|
|
180
|
-
* @param options Merging options
|
|
181
|
-
* @returns Merged value
|
|
182
|
-
*/
|
|
183
|
-
export function merge<Values extends ArrayOrPlainObject[]>(
|
|
184
|
-
values: [...Values],
|
|
185
|
-
options?: MergeOptions,
|
|
186
|
-
): UnionToIntersection<Values[number]> {
|
|
187
|
-
return mergeValues(values, getMergeOptions(options)) as UnionToIntersection<Values[number]>;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
merge.initialize = initializeMerger;
|
|
191
|
-
|
|
192
|
-
function mergeObjects(
|
|
193
|
-
values: ArrayOrPlainObject[],
|
|
194
|
-
options: Options,
|
|
195
|
-
destination?: ArrayOrPlainObject,
|
|
196
|
-
prefix?: string,
|
|
197
|
-
): ArrayOrPlainObject {
|
|
198
|
-
const {length} = values;
|
|
199
|
-
|
|
200
|
-
const isArray = Array.isArray(destination ?? values[0]);
|
|
201
|
-
const merged = (destination ?? (isArray ? [] : {})) as PlainObject;
|
|
202
|
-
|
|
203
|
-
const offset = destination == null ? 0 : 1;
|
|
204
|
-
|
|
205
|
-
for (let outerIndex = offset; outerIndex < length; outerIndex += 1) {
|
|
206
|
-
const item = values[outerIndex] as PlainObject;
|
|
207
|
-
const keys = Object.keys(item);
|
|
208
|
-
const size = keys.length;
|
|
209
|
-
|
|
210
|
-
for (let innerIndex = 0; innerIndex < size; innerIndex += 1) {
|
|
211
|
-
const key = keys[innerIndex];
|
|
212
|
-
|
|
213
|
-
const next = item[key];
|
|
214
|
-
const previous = merged[key];
|
|
215
|
-
|
|
216
|
-
if (next == null && (options.skipNullableAny || (isArray && options.skipNullableInArrays))) {
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const full =
|
|
221
|
-
options.replaceableObjects == null ? undefined : prefix == null ? key : `${prefix}.${key}`;
|
|
222
|
-
|
|
223
|
-
if (
|
|
224
|
-
isArrayOrPlainObject(next) &&
|
|
225
|
-
isArrayOrPlainObject(previous) &&
|
|
226
|
-
!(options.replaceableObjects?.(full!) ?? false)
|
|
227
|
-
) {
|
|
228
|
-
merged[key] = mergeObjects(
|
|
229
|
-
[previous, next],
|
|
230
|
-
options,
|
|
231
|
-
(destination == null ? undefined : merged[key]) as ArrayOrPlainObject,
|
|
232
|
-
full,
|
|
233
|
-
);
|
|
234
|
-
} else {
|
|
235
|
-
merged[key] = next;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return merged;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function mergeValues(
|
|
244
|
-
values: ArrayOrPlainObject[],
|
|
245
|
-
options: Options,
|
|
246
|
-
prefix?: string,
|
|
247
|
-
): ArrayOrPlainObject {
|
|
248
|
-
if (!Array.isArray(values)) {
|
|
249
|
-
return {};
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const actual = values.filter(isArrayOrPlainObject);
|
|
253
|
-
|
|
254
|
-
if (actual.length === 0) {
|
|
255
|
-
return {};
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (
|
|
259
|
-
options.assignValues &&
|
|
260
|
-
actual.length === 2 &&
|
|
261
|
-
!Array.isArray(actual[0]) &&
|
|
262
|
-
Object.keys(actual[0]).length === 0
|
|
263
|
-
) {
|
|
264
|
-
return Object.assign(actual[0], actual[1]);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (actual.length > 1) {
|
|
268
|
-
return mergeObjects(actual, options, options.assignValues ? actual[0] : undefined, prefix);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return options.assignValues
|
|
272
|
-
? actual[0]
|
|
273
|
-
: Array.isArray(actual[0])
|
|
274
|
-
? actual[0].slice()
|
|
275
|
-
: {...actual[0]};
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// #endregion
|
package/src/value/omit.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {partial} from '../internal/value/partial';
|
|
2
|
-
import type {PlainObject} from '../models';
|
|
3
|
-
|
|
4
|
-
// #region Functions
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Create a new object without the specified keys
|
|
8
|
-
*
|
|
9
|
-
* @param value Original object
|
|
10
|
-
* @param keys Keys to omit
|
|
11
|
-
* @returns Partial object without the specified keys
|
|
12
|
-
*/
|
|
13
|
-
export function omit<Value extends PlainObject, ValueKey extends keyof Value>(
|
|
14
|
-
value: Value,
|
|
15
|
-
keys: ValueKey[],
|
|
16
|
-
): Omit<Value, ValueKey> {
|
|
17
|
-
return partial(value, keys, true);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// #endregion
|
package/src/value/pick.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {partial} from '../internal/value/partial';
|
|
2
|
-
import type {PlainObject} from '../models';
|
|
3
|
-
|
|
4
|
-
// #region Functions
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Create a new object with only the specified keys
|
|
8
|
-
*
|
|
9
|
-
* @param value Original object
|
|
10
|
-
* @param keys Keys to use
|
|
11
|
-
* @returns Partial object with only the specified keys
|
|
12
|
-
*/
|
|
13
|
-
export function pick<Value extends PlainObject, ValueKey extends keyof Value>(
|
|
14
|
-
value: Value,
|
|
15
|
-
keys: ValueKey[],
|
|
16
|
-
): Pick<Value, ValueKey> {
|
|
17
|
-
return partial(value, keys, false);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// #endregion
|
package/src/value/shake.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {isNonPlainObject} from '../internal/is';
|
|
2
|
-
import type {PlainObject} from '../models';
|
|
3
|
-
|
|
4
|
-
// #region Types
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A shaken object, without any `undefined` values
|
|
8
|
-
*/
|
|
9
|
-
export type Shaken<Value extends PlainObject> = {
|
|
10
|
-
[Key in keyof Value]: Value[Key] extends undefined ? never : Value[Key];
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// #endregion
|
|
14
|
-
|
|
15
|
-
// #region Functions
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Shake an object, removing all keys with `undefined` values
|
|
19
|
-
*
|
|
20
|
-
* @param value Object to shake
|
|
21
|
-
* @returns Shaken object
|
|
22
|
-
*/
|
|
23
|
-
export function shake<Value extends PlainObject>(value: Value): Shaken<Value> {
|
|
24
|
-
const shaken: PlainObject = {};
|
|
25
|
-
|
|
26
|
-
if (isNonPlainObject(value)) {
|
|
27
|
-
return shaken as Shaken<Value>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const keys = Object.keys(value) as (keyof Value)[];
|
|
31
|
-
const {length} = keys;
|
|
32
|
-
|
|
33
|
-
for (let index = 0; index < length; index += 1) {
|
|
34
|
-
const key = keys[index];
|
|
35
|
-
const val = value[key];
|
|
36
|
-
|
|
37
|
-
if (val !== undefined) {
|
|
38
|
-
shaken[key] = val;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return shaken as Shaken<Value>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// #endregion
|