qidian-shared 1.0.74 → 1.0.75
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/utils/common.d.ts +1 -1
- package/dist/utils/common.mjs +19 -2
- package/package.json +1 -1
package/dist/utils/common.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export declare function extractSlotsWithPrefix(slots: SetupContext['slots'], pre
|
|
|
36
36
|
}[];
|
|
37
37
|
export declare function extractSlotsWithoutPrefix(slots: SetupContext['slots'], prefix: string): string[];
|
|
38
38
|
export declare function filterSlots(slots: SetupContext['slots'], filterName: string[]): string[];
|
|
39
|
-
export declare function easyCopy<T>(data: T): T;
|
|
39
|
+
export declare function easyCopy<T>(data: T, reviver?: (key: string, value: any) => any): T;
|
|
40
40
|
export declare function checkSameObject(newData: unknown, oldData: unknown): boolean;
|
|
41
41
|
export declare function valueFillter(val: string, keys: string, data: Record<string, string | number>): string;
|
|
42
42
|
type Simplify<T> = T extends any ? {
|
package/dist/utils/common.mjs
CHANGED
|
@@ -66,8 +66,25 @@ function filterSlots(slots, filterName) {
|
|
|
66
66
|
}
|
|
67
67
|
return res;
|
|
68
68
|
}
|
|
69
|
-
function easyCopy(data) {
|
|
70
|
-
|
|
69
|
+
function easyCopy(data, reviver) {
|
|
70
|
+
if (!data) return data;
|
|
71
|
+
const undefinedKey = `__QD_EASY_COPY_UNDEFINED_${(/* @__PURE__ */ new Date()).getTime()}__`;
|
|
72
|
+
const res = JSON.parse(
|
|
73
|
+
JSON.stringify(data, (key, value) => {
|
|
74
|
+
const reVal = reviver ? reviver(key, value) : value;
|
|
75
|
+
return reVal === void 0 ? undefinedKey : reVal;
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
return restoreUndefined(res);
|
|
79
|
+
function restoreUndefined(value) {
|
|
80
|
+
if (value === undefinedKey) return void 0;
|
|
81
|
+
if (Array.isArray(value)) {
|
|
82
|
+
for (let i = 0; i < value.length; i++) value[i] = restoreUndefined(value[i]);
|
|
83
|
+
} else if (value && typeof value === "object") {
|
|
84
|
+
for (const key in value) value[key] = restoreUndefined(value[key]);
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
71
88
|
}
|
|
72
89
|
function checkSameObject(newData, oldData) {
|
|
73
90
|
if (newData && !oldData || !newData && oldData || typeof newData !== typeof oldData) {
|