@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.
- package/dist/array/filter.d.mts +4 -4
- package/dist/array/find.d.mts +4 -4
- package/dist/array/first.d.mts +4 -4
- package/dist/array/get.d.mts +27 -1
- package/dist/array/get.mjs +5 -3
- package/dist/array/group-by.d.mts +6 -6
- package/dist/array/last.d.mts +4 -4
- package/dist/array/match.d.mts +7 -6
- package/dist/array/move.d.mts +7 -7
- package/dist/array/move.mjs +1 -1
- package/dist/array/select.d.mts +1 -0
- package/dist/array/slice.d.mts +3 -3
- package/dist/array/sort.d.mts +10 -7
- package/dist/array/sort.mjs +4 -3
- package/dist/array/swap.d.mts +1 -1
- package/dist/array/swap.mjs +1 -1
- package/dist/array/to-map.d.mts +32 -32
- package/dist/array/to-record.d.mts +6 -6
- package/dist/array/to-set.d.mts +6 -6
- package/dist/beacon.d.mts +6 -0
- package/dist/beacon.mjs +3 -0
- package/dist/color/index.d.mts +6 -2
- package/dist/color/index.mjs +6 -2
- package/dist/color/instance.d.mts +78 -14
- package/dist/color/instance.mjs +78 -14
- package/dist/color/misc/get.d.mts +39 -11
- package/dist/color/misc/get.mjs +39 -11
- package/dist/color/misc/is.d.mts +26 -11
- package/dist/color/misc/is.mjs +26 -11
- package/dist/color/misc/state.mjs +1 -1
- package/dist/color/models.d.mts +7 -4
- package/dist/color/space/hex.d.mts +15 -6
- package/dist/color/space/hex.mjs +15 -6
- package/dist/color/space/hsl.d.mts +10 -4
- package/dist/color/space/hsl.mjs +10 -4
- package/dist/color/space/rgb.d.mts +21 -12
- package/dist/color/space/rgb.mjs +21 -12
- package/dist/function/assert.d.mts +20 -14
- package/dist/function/assert.mjs +19 -13
- package/dist/function/limit.d.mts +8 -6
- package/dist/function/limit.mjs +8 -6
- package/dist/function/memoize.d.mts +15 -4
- package/dist/function/memoize.mjs +18 -4
- package/dist/function/once.d.mts +5 -3
- package/dist/function/once.mjs +5 -3
- package/dist/function/retry.d.mts +5 -2
- package/dist/function/retry.mjs +3 -1
- package/dist/function/work.d.mts +146 -98
- package/dist/{kalas.d.mts → herald.d.mts} +17 -8
- package/dist/{kalas.mjs → herald.mjs} +22 -13
- package/dist/index.d.mts +1464 -708
- package/dist/index.mjs +677 -324
- package/dist/internal/array/index-of.d.mts +4 -4
- package/dist/internal/array/insert.mjs +1 -1
- package/dist/internal/array/shuffle.d.mts +1 -0
- package/dist/internal/array/shuffle.mjs +2 -1
- package/dist/internal/is.d.mts +26 -8
- package/dist/internal/is.mjs +26 -8
- package/dist/internal/math/aggregate.d.mts +9 -9
- package/dist/internal/number.d.mts +13 -2
- package/dist/internal/number.mjs +13 -2
- package/dist/internal/random.d.mts +4 -2
- package/dist/internal/random.mjs +7 -5
- package/dist/internal/result.d.mts +17 -11
- package/dist/internal/result.mjs +10 -14
- package/dist/internal/string.d.mts +16 -1
- package/dist/internal/string.mjs +24 -1
- package/dist/internal/value/compare.d.mts +5 -2
- package/dist/internal/value/compare.mjs +5 -2
- package/dist/internal/value/equal.d.mts +12 -3
- package/dist/internal/value/equal.mjs +7 -4
- package/dist/internal/value/get.d.mts +17 -17
- package/dist/internal/value/has.d.mts +55 -11
- package/dist/internal/value/set.d.mts +24 -0
- package/dist/is.d.mts +12 -0
- package/dist/is.mjs +16 -1
- package/dist/logger.d.mts +7 -6
- package/dist/logger.mjs +6 -5
- package/dist/math.d.mts +36 -18
- package/dist/math.mjs +6 -3
- package/dist/models.d.mts +3 -3
- package/dist/promise/delay.d.mts +2 -0
- package/dist/promise/helpers.d.mts +6 -4
- package/dist/promise/helpers.mjs +6 -4
- package/dist/promise/index.d.mts +49 -38
- package/dist/promise/misc.d.mts +10 -7
- package/dist/promise/misc.mjs +4 -3
- package/dist/promise/models.d.mts +18 -19
- package/dist/promise/models.mjs +4 -3
- package/dist/promise/timed.d.mts +8 -6
- package/dist/query.d.mts +2 -0
- package/dist/query.mjs +2 -0
- package/dist/queue.d.mts +15 -4
- package/dist/queue.mjs +10 -3
- package/dist/random.d.mts +9 -2
- package/dist/random.mjs +7 -2
- package/dist/result/index.d.mts +14 -8
- package/dist/result/match.d.mts +18 -10
- package/dist/result/misc.d.mts +14 -7
- package/dist/result/misc.mjs +4 -2
- package/dist/result/models.d.mts +2 -0
- package/dist/result/work/flow.d.mts +86 -62
- package/dist/result/work/pipe.d.mts +55 -33
- package/dist/sized/map.d.mts +19 -16
- package/dist/sized/map.mjs +4 -4
- package/dist/sized/set.d.mts +20 -16
- package/dist/sized/set.mjs +8 -7
- package/dist/string/case.d.mts +8 -0
- package/dist/string/case.mjs +8 -0
- package/dist/string/fuzzy.d.mts +19 -5
- package/dist/string/fuzzy.mjs +7 -0
- package/dist/string/index.d.mts +17 -2
- package/dist/string/index.mjs +7 -9
- package/dist/string/match.d.mts +3 -0
- package/dist/string/match.mjs +3 -0
- package/dist/string/normalize.d.mts +6 -2
- package/dist/string/normalize.mjs +5 -2
- package/dist/string/template.d.mts +38 -9
- package/dist/string/template.mjs +19 -19
- package/dist/value/clone.d.mts +25 -4
- package/dist/value/clone.mjs +36 -22
- package/dist/value/collection.d.mts +9 -6
- package/dist/value/collection.mjs +3 -2
- package/dist/value/diff.d.mts +3 -1
- package/dist/value/diff.mjs +1 -0
- package/dist/value/freeze.d.mts +118 -9
- package/dist/value/freeze.mjs +56 -14
- package/dist/value/index.d.mts +1 -2
- package/dist/value/index.mjs +1 -2
- package/dist/value/merge.d.mts +11 -5
- package/dist/value/merge.mjs +2 -2
- package/dist/value/omit.d.mts +1 -0
- package/dist/value/omit.mjs +1 -0
- package/dist/value/pick.d.mts +1 -0
- package/dist/value/pick.mjs +1 -0
- package/dist/value/shake.d.mts +1 -0
- package/dist/value/shake.mjs +1 -0
- package/dist/value/smush.d.mts +1 -0
- package/dist/value/smush.mjs +1 -0
- package/dist/value/transform.d.mts +7 -3
- package/dist/value/unsmush.d.mts +1 -0
- package/dist/value/unsmush.mjs +1 -0
- package/package.json +11 -7
- package/src/array/filter.ts +4 -4
- package/src/array/find.ts +4 -4
- package/src/array/first.ts +4 -4
- package/src/array/get.ts +40 -5
- package/src/array/group-by.ts +6 -6
- package/src/array/last.ts +4 -4
- package/src/array/match.ts +7 -6
- package/src/array/move.ts +7 -7
- package/src/array/select.ts +1 -0
- package/src/array/slice.ts +3 -3
- package/src/array/sort.ts +15 -10
- package/src/array/swap.ts +1 -1
- package/src/array/to-map.ts +32 -32
- package/src/array/to-record.ts +6 -6
- package/src/array/to-set.ts +6 -6
- package/src/beacon.ts +6 -0
- package/src/color/index.ts +6 -2
- package/src/color/instance.ts +78 -14
- package/src/color/misc/get.ts +39 -11
- package/src/color/misc/is.ts +26 -11
- package/src/color/misc/state.ts +1 -1
- package/src/color/models.ts +7 -4
- package/src/color/space/hex.ts +15 -6
- package/src/color/space/hsl.ts +10 -4
- package/src/color/space/rgb.ts +21 -12
- package/src/function/assert.ts +20 -14
- package/src/function/limit.ts +8 -6
- package/src/function/memoize.ts +24 -5
- package/src/function/once.ts +5 -3
- package/src/function/retry.ts +7 -3
- package/src/function/work.ts +146 -98
- package/src/{kalas.ts → herald.ts} +23 -14
- package/src/index.ts +3 -2
- package/src/internal/array/index-of.ts +4 -4
- package/src/internal/array/insert.ts +1 -1
- package/src/internal/array/shuffle.ts +2 -1
- package/src/internal/is.ts +26 -8
- package/src/internal/math/aggregate.ts +9 -9
- package/src/internal/number.ts +13 -2
- package/src/internal/random.ts +10 -4
- package/src/internal/result.ts +30 -29
- package/src/internal/string.ts +28 -0
- package/src/internal/value/compare.ts +5 -2
- package/src/internal/value/equal.ts +13 -4
- package/src/internal/value/get.ts +17 -17
- package/src/internal/value/has.ts +54 -11
- package/src/internal/value/set.ts +24 -0
- package/src/is.ts +15 -1
- package/src/logger.ts +8 -7
- package/src/math.ts +36 -18
- package/src/models.ts +3 -3
- package/src/promise/delay.ts +2 -0
- package/src/promise/helpers.ts +6 -4
- package/src/promise/index.ts +49 -38
- package/src/promise/misc.ts +10 -7
- package/src/promise/models.ts +18 -19
- package/src/promise/timed.ts +8 -6
- package/src/query.ts +2 -0
- package/src/queue.ts +15 -4
- package/src/random.ts +8 -1
- package/src/result/index.ts +14 -8
- package/src/result/match.ts +18 -10
- package/src/result/misc.ts +17 -9
- package/src/result/models.ts +2 -0
- package/src/result/work/flow.ts +86 -62
- package/src/result/work/pipe.ts +55 -33
- package/src/sized/map.ts +20 -17
- package/src/sized/set.ts +21 -17
- package/src/string/case.ts +8 -0
- package/src/string/fuzzy.ts +19 -5
- package/src/string/index.ts +18 -15
- package/src/string/match.ts +3 -0
- package/src/string/normalize.ts +6 -2
- package/src/string/template.ts +69 -18
- package/src/value/clone.ts +51 -26
- package/src/value/collection.ts +9 -6
- package/src/value/diff.ts +3 -1
- package/src/value/freeze.ts +239 -25
- package/src/value/index.ts +0 -1
- package/src/value/merge.ts +11 -5
- package/src/value/omit.ts +1 -0
- package/src/value/pick.ts +1 -0
- package/src/value/shake.ts +1 -0
- package/src/value/smush.ts +1 -0
- package/src/value/transform.ts +7 -3
- package/src/value/unsmush.ts +1 -0
package/dist/value/clone.mjs
CHANGED
|
@@ -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
|
|
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:
|
|
79
|
-
case typeof value === "bigint":
|
|
80
|
-
case typeof value === "boolean":
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
4
|
-
*
|
|
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
|
|
11
|
-
*
|
|
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
|
|
19
|
-
*
|
|
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
|
|
11
|
-
*
|
|
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
|
*/
|
package/dist/value/diff.d.mts
CHANGED
|
@@ -21,7 +21,8 @@ type DiffResult<First, Second = First> = {
|
|
|
21
21
|
*/
|
|
22
22
|
type: DiffType;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
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
|
package/dist/value/diff.mjs
CHANGED
package/dist/value/freeze.d.mts
CHANGED
|
@@ -1,35 +1,144 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
|
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
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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<
|
|
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,
|
|
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 };
|
package/dist/value/freeze.mjs
CHANGED
|
@@ -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
|
|
4
|
-
return
|
|
4
|
+
function fakeDelete() {
|
|
5
|
+
return false;
|
|
5
6
|
}
|
|
6
|
-
function
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
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
|
|
32
|
-
case
|
|
33
|
-
case
|
|
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 };
|
package/dist/value/index.d.mts
CHANGED
|
@@ -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
|
|
6
|
+
export { type Shaken, type Smushed, type Unsmushed, omit, pick, shake, smush, unsmush };
|
package/dist/value/index.mjs
CHANGED
|
@@ -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 {
|
|
6
|
+
export { omit, pick, shake, smush, unsmush };
|
package/dist/value/merge.d.mts
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
90
|
+
* _Available as `initializeMerger` and `merge.initialize`_
|
|
85
91
|
*
|
|
86
92
|
* @param options Merging options
|
|
87
93
|
* @returns Merger function
|
package/dist/value/merge.mjs
CHANGED
|
@@ -35,7 +35,7 @@ function getReplaceableObjects(value) {
|
|
|
35
35
|
/**
|
|
36
36
|
* Create an assigner with predefined options
|
|
37
37
|
*
|
|
38
|
-
*
|
|
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
|
-
*
|
|
51
|
+
* _Available as `initializeMerger` and `merge.initialize`_
|
|
52
52
|
*
|
|
53
53
|
* @param options Merging options
|
|
54
54
|
* @returns Merger function
|
package/dist/value/omit.d.mts
CHANGED
package/dist/value/omit.mjs
CHANGED
package/dist/value/pick.d.mts
CHANGED
package/dist/value/pick.mjs
CHANGED
package/dist/value/shake.d.mts
CHANGED
|
@@ -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
|
*/
|
package/dist/value/shake.mjs
CHANGED
package/dist/value/smush.d.mts
CHANGED
|
@@ -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
|
*/
|
package/dist/value/smush.mjs
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|