@e-mc/types 0.12.9 → 0.12.11
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/README.md +7 -6
- package/constant.d.ts +1 -1
- package/index.d.ts +4 -2
- package/index.js +37 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.12.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.12.11/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogArguments } from "./lib/logger";
|
|
@@ -56,7 +56,8 @@ function formatSize(value: number, options?: BytesOptions): string;
|
|
|
56
56
|
function alignSize(value: unknown, kb?: number, factor?: number): number;
|
|
57
57
|
function cascadeObject(data: object, query: string, fallback?: unknown): unknown;
|
|
58
58
|
function cloneObject(data: unknown, deep: boolean): unknown;
|
|
59
|
-
|
|
59
|
+
/** @deprecated WeakMap<object> */
|
|
60
|
+
function cloneObject<T>(data: T, deepIgnore: WeakSet<object> | WeakMap<object, object>): T;
|
|
60
61
|
function cloneObject(data: unknown, options?: CloneObjectOptions<unknown>): unknown;
|
|
61
62
|
function coerceObject(data: unknown, cache: boolean): unknown;
|
|
62
63
|
function coerceObject(data: unknown, parseString?: (...args: [string]) => unknown, cache?: boolean): unknown;
|
|
@@ -203,10 +204,10 @@ const IMPORT_MAP: Record<string, string | undefined>;
|
|
|
203
204
|
|
|
204
205
|
## References
|
|
205
206
|
|
|
206
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
207
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
208
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
209
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
207
|
+
- https://www.unpkg.com/@e-mc/types@0.12.11/index.d.ts
|
|
208
|
+
- https://www.unpkg.com/@e-mc/types@0.12.11/lib/logger.d.ts
|
|
209
|
+
- https://www.unpkg.com/@e-mc/types@0.12.11/lib/module.d.ts
|
|
210
|
+
- https://www.unpkg.com/@e-mc/types@0.12.11/lib/node.d.ts
|
|
210
211
|
|
|
211
212
|
* https://developer.mozilla.org/en-US/docs/Web/API/DOMException
|
|
212
213
|
* https://www.npmjs.com/package/@types/bytes
|
package/constant.d.ts
CHANGED
package/index.d.ts
CHANGED
|
@@ -269,7 +269,8 @@ declare namespace types {
|
|
|
269
269
|
interface CloneObjectOptions<T = unknown> {
|
|
270
270
|
target?: T;
|
|
271
271
|
deep?: boolean;
|
|
272
|
-
|
|
272
|
+
/** @deprecated WeakSet<object> */
|
|
273
|
+
deepIgnore?: WeakSet<object> | WeakMap<object, object>;
|
|
273
274
|
freezeDepth?: number | boolean;
|
|
274
275
|
mergeArray?: MergeArrayMethod;
|
|
275
276
|
mergeDepth?: number;
|
|
@@ -324,7 +325,8 @@ declare namespace types {
|
|
|
324
325
|
function alignSize(value: unknown, kb?: number, factor?: number): number;
|
|
325
326
|
function cascadeObject<T = unknown>(data: object, query: string, fallback?: unknown): T;
|
|
326
327
|
function cloneObject<T>(data: T, deep: boolean): T;
|
|
327
|
-
|
|
328
|
+
/** @deprecated WeakMap<object> */
|
|
329
|
+
function cloneObject<T>(data: T, deepIgnore: WeakSet<object> | WeakMap<object, object>): T;
|
|
328
330
|
function cloneObject<T, U>(data: T, options?: CloneObjectOptions<U>): T;
|
|
329
331
|
function coerceObject<T = unknown>(data: T, cache: boolean): T;
|
|
330
332
|
function coerceObject<T = unknown>(data: T, parseString?: FunctionArgs<[string]>, cache?: boolean): T;
|
package/index.js
CHANGED
|
@@ -865,7 +865,7 @@ function cloneObject(data, options) {
|
|
|
865
865
|
if (options === true) {
|
|
866
866
|
deep = true;
|
|
867
867
|
}
|
|
868
|
-
else if (options instanceof WeakSet) {
|
|
868
|
+
else if (options instanceof WeakSet || options instanceof WeakMap) {
|
|
869
869
|
deep = true;
|
|
870
870
|
structured = true;
|
|
871
871
|
deepIgnore = options;
|
|
@@ -884,11 +884,13 @@ function cloneObject(data, options) {
|
|
|
884
884
|
}
|
|
885
885
|
let nested;
|
|
886
886
|
if (deep || freezeDepth > 0) {
|
|
887
|
-
deepIgnore ||= new
|
|
887
|
+
deepIgnore ||= new WeakMap();
|
|
888
888
|
nested = { deep, deepIgnore, freezeDepth, mergeArray, mergeDepth, typedArray, structured, preserve };
|
|
889
889
|
}
|
|
890
890
|
if (Array.isArray(data)) {
|
|
891
|
-
deepIgnore
|
|
891
|
+
if (deepIgnore instanceof WeakSet) {
|
|
892
|
+
deepIgnore.add(data);
|
|
893
|
+
}
|
|
892
894
|
const length = data.length;
|
|
893
895
|
if (Array.isArray(target)) {
|
|
894
896
|
if (mergeArray && mergeDepth >= 0 && !(mergeArray === 'join' || Array.isArray(mergeArray) && mergeArray[0] === 'join')) {
|
|
@@ -902,18 +904,33 @@ function cloneObject(data, options) {
|
|
|
902
904
|
else {
|
|
903
905
|
target = new Array(length);
|
|
904
906
|
}
|
|
905
|
-
for (let i = 0; i < length; ++i) {
|
|
907
|
+
for (let i = 0, merge; i < length; ++i) {
|
|
906
908
|
const value = data[i];
|
|
907
909
|
if (deepIgnore) {
|
|
908
|
-
|
|
910
|
+
const found = deepIgnore.has(value);
|
|
911
|
+
if (found && deepIgnore instanceof WeakMap) {
|
|
912
|
+
merge = deepIgnore.get(value);
|
|
913
|
+
}
|
|
914
|
+
else if (!found && (Array.isArray(value) || isPlainObject(value))) {
|
|
915
|
+
merge = cloneObject(value, nested);
|
|
916
|
+
if (deepIgnore instanceof WeakMap) {
|
|
917
|
+
deepIgnore.set(value, merge);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
else {
|
|
921
|
+
merge = fromObject(value, typedArray, structured, shared);
|
|
922
|
+
}
|
|
909
923
|
}
|
|
910
924
|
else {
|
|
911
|
-
|
|
925
|
+
merge = Array.isArray(value) ? value.slice(0) : value;
|
|
912
926
|
}
|
|
927
|
+
target[i] = merge;
|
|
913
928
|
}
|
|
914
929
|
}
|
|
915
930
|
else if (isObject(data)) {
|
|
916
|
-
deepIgnore
|
|
931
|
+
if (deepIgnore instanceof WeakSet) {
|
|
932
|
+
deepIgnore.add(data);
|
|
933
|
+
}
|
|
917
934
|
if (!isObject(target)) {
|
|
918
935
|
target = {};
|
|
919
936
|
}
|
|
@@ -921,7 +938,19 @@ function cloneObject(data, options) {
|
|
|
921
938
|
const value = data[attr];
|
|
922
939
|
let merge;
|
|
923
940
|
if (deepIgnore) {
|
|
924
|
-
|
|
941
|
+
const found = deepIgnore.has(value);
|
|
942
|
+
if (found && deepIgnore instanceof WeakMap) {
|
|
943
|
+
merge = deepIgnore.get(value);
|
|
944
|
+
}
|
|
945
|
+
else if (!found && (Array.isArray(value) || isPlainObject(value))) {
|
|
946
|
+
merge = cloneObject(value, nested);
|
|
947
|
+
if (deepIgnore instanceof WeakMap) {
|
|
948
|
+
deepIgnore.set(value, merge);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
else {
|
|
952
|
+
merge = fromObject(value, typedArray, structured, shared);
|
|
953
|
+
}
|
|
925
954
|
}
|
|
926
955
|
else {
|
|
927
956
|
merge = Array.isArray(value) ? value.slice(0) : value;
|