@e-mc/types 0.13.2 → 0.13.4
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.13.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.13.4/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogArguments } from "./lib/logger";
|
|
@@ -60,7 +60,8 @@ function formatSize(value: number, options?: BytesOptions): string;
|
|
|
60
60
|
function alignSize(value: unknown, kb?: number, factor?: number): number;
|
|
61
61
|
function cascadeObject(data: object, query: string, fallback?: unknown): unknown;
|
|
62
62
|
function cloneObject(data: unknown, deep: boolean): unknown;
|
|
63
|
-
|
|
63
|
+
/** @deprecated WeakMap<object> */
|
|
64
|
+
function cloneObject<T>(data: T, deepIgnore: WeakSet<object> | WeakMap<object, object>): T;
|
|
64
65
|
function cloneObject(data: unknown, options?: CloneObjectOptions<unknown>): unknown;
|
|
65
66
|
function coerceObject(data: unknown, cache: boolean): unknown;
|
|
66
67
|
function coerceObject(data: unknown, parseString?: (...args: [string]) => unknown, cache?: boolean): unknown;
|
|
@@ -207,10 +208,10 @@ const IMPORT_MAP: Record<string, string | undefined>;
|
|
|
207
208
|
|
|
208
209
|
## References
|
|
209
210
|
|
|
210
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
211
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
212
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
213
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
211
|
+
- https://www.unpkg.com/@e-mc/types@0.13.4/index.d.ts
|
|
212
|
+
- https://www.unpkg.com/@e-mc/types@0.13.4/lib/logger.d.ts
|
|
213
|
+
- https://www.unpkg.com/@e-mc/types@0.13.4/lib/module.d.ts
|
|
214
|
+
- https://www.unpkg.com/@e-mc/types@0.13.4/lib/node.d.ts
|
|
214
215
|
|
|
215
216
|
* https://developer.mozilla.org/en-US/docs/Web/API/DOMException
|
|
216
217
|
* 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;
|
|
@@ -328,7 +329,8 @@ declare namespace types {
|
|
|
328
329
|
function alignSize(value: unknown, kb?: number, factor?: number): number;
|
|
329
330
|
function cascadeObject<T = unknown>(data: object, query: string, fallback?: unknown): T;
|
|
330
331
|
function cloneObject<T>(data: T, deep: boolean): T;
|
|
331
|
-
|
|
332
|
+
/** @deprecated WeakMap<object> */
|
|
333
|
+
function cloneObject<T>(data: T, deepIgnore: WeakSet<object> | WeakMap<object, object>): T;
|
|
332
334
|
function cloneObject<T, U>(data: T, options?: CloneObjectOptions<U>): T;
|
|
333
335
|
function coerceObject<T = unknown>(data: T, cache: boolean): T;
|
|
334
336
|
function coerceObject<T = unknown>(data: T, parseString?: FunctionArgs<[string]>, cache?: boolean): T;
|
package/index.js
CHANGED
|
@@ -888,7 +888,7 @@ function cloneObject(data, options) {
|
|
|
888
888
|
if (options === true) {
|
|
889
889
|
deep = true;
|
|
890
890
|
}
|
|
891
|
-
else if (options instanceof WeakSet) {
|
|
891
|
+
else if (options instanceof WeakSet || options instanceof WeakMap) {
|
|
892
892
|
deep = true;
|
|
893
893
|
structured = true;
|
|
894
894
|
deepIgnore = options;
|
|
@@ -907,11 +907,13 @@ function cloneObject(data, options) {
|
|
|
907
907
|
}
|
|
908
908
|
let nested;
|
|
909
909
|
if (deep || freezeDepth > 0) {
|
|
910
|
-
deepIgnore ||= new
|
|
910
|
+
deepIgnore ||= new WeakMap();
|
|
911
911
|
nested = { deep, deepIgnore, freezeDepth, mergeArray, mergeDepth, typedArray, structured, preserve };
|
|
912
912
|
}
|
|
913
913
|
if (Array.isArray(data)) {
|
|
914
|
-
deepIgnore
|
|
914
|
+
if (deepIgnore instanceof WeakSet) {
|
|
915
|
+
deepIgnore.add(data);
|
|
916
|
+
}
|
|
915
917
|
const length = data.length;
|
|
916
918
|
if (Array.isArray(target)) {
|
|
917
919
|
if (mergeArray && mergeDepth >= 0 && !(mergeArray === 'join' || Array.isArray(mergeArray) && mergeArray[0] === 'join')) {
|
|
@@ -925,18 +927,33 @@ function cloneObject(data, options) {
|
|
|
925
927
|
else {
|
|
926
928
|
target = new Array(length);
|
|
927
929
|
}
|
|
928
|
-
for (let i = 0; i < length; ++i) {
|
|
930
|
+
for (let i = 0, merge; i < length; ++i) {
|
|
929
931
|
const value = data[i];
|
|
930
932
|
if (deepIgnore) {
|
|
931
|
-
|
|
933
|
+
const found = deepIgnore.has(value);
|
|
934
|
+
if (found && deepIgnore instanceof WeakMap) {
|
|
935
|
+
merge = deepIgnore.get(value);
|
|
936
|
+
}
|
|
937
|
+
else if (!found && (Array.isArray(value) || isPlainObject(value))) {
|
|
938
|
+
merge = cloneObject(value, nested);
|
|
939
|
+
if (deepIgnore instanceof WeakMap) {
|
|
940
|
+
deepIgnore.set(value, merge);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
else {
|
|
944
|
+
merge = fromObject(value, typedArray, structured, shared);
|
|
945
|
+
}
|
|
932
946
|
}
|
|
933
947
|
else {
|
|
934
|
-
|
|
948
|
+
merge = Array.isArray(value) ? value.slice(0) : value;
|
|
935
949
|
}
|
|
950
|
+
target[i] = merge;
|
|
936
951
|
}
|
|
937
952
|
}
|
|
938
953
|
else if (isObject(data)) {
|
|
939
|
-
deepIgnore
|
|
954
|
+
if (deepIgnore instanceof WeakSet) {
|
|
955
|
+
deepIgnore.add(data);
|
|
956
|
+
}
|
|
940
957
|
if (!isObject(target)) {
|
|
941
958
|
target = {};
|
|
942
959
|
}
|
|
@@ -944,7 +961,19 @@ function cloneObject(data, options) {
|
|
|
944
961
|
const value = data[attr];
|
|
945
962
|
let merge;
|
|
946
963
|
if (deepIgnore) {
|
|
947
|
-
|
|
964
|
+
const found = deepIgnore.has(value);
|
|
965
|
+
if (found && deepIgnore instanceof WeakMap) {
|
|
966
|
+
merge = deepIgnore.get(value);
|
|
967
|
+
}
|
|
968
|
+
else if (!found && (Array.isArray(value) || isPlainObject(value))) {
|
|
969
|
+
merge = cloneObject(value, nested);
|
|
970
|
+
if (deepIgnore instanceof WeakMap) {
|
|
971
|
+
deepIgnore.set(value, merge);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
else {
|
|
975
|
+
merge = fromObject(value, typedArray, structured, shared);
|
|
976
|
+
}
|
|
948
977
|
}
|
|
949
978
|
else {
|
|
950
979
|
merge = Array.isArray(value) ? value.slice(0) : value;
|