@whitesev/utils 2.9.6 → 2.9.8
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/index.amd.js +38 -29
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +38 -29
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +38 -29
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +38 -29
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +38 -29
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +38 -29
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Utils.d.ts +6 -2
- package/package.json +9 -9
- package/src/CommonUtil.ts +36 -31
- package/src/Utils.ts +7 -2
package/dist/index.cjs.js
CHANGED
|
@@ -312,38 +312,44 @@ class CommonUtil {
|
|
|
312
312
|
if (target == null) {
|
|
313
313
|
target = {};
|
|
314
314
|
}
|
|
315
|
+
// 当前遍历的目标对象
|
|
316
|
+
let iteratorTarget;
|
|
315
317
|
if (isAdd) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const targetValue = Reflect.get(target, targetKeyName);
|
|
319
|
-
const sourceValue = Reflect.get(source, sourceKeyName);
|
|
320
|
-
if (typeof sourceValue === "object" &&
|
|
321
|
-
sourceValue != null &&
|
|
322
|
-
sourceKeyName in target &&
|
|
323
|
-
!UtilsContext.isDOM(sourceValue)) {
|
|
324
|
-
/* 源端的值是object类型,且不是元素节点 */
|
|
325
|
-
Reflect.set(target, sourceKeyName, UtilsContext.assign(targetValue, sourceValue, isAdd));
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
Reflect.set(target, sourceKeyName, sourceValue);
|
|
329
|
-
}
|
|
318
|
+
// 追加并覆盖是以source为准
|
|
319
|
+
iteratorTarget = source;
|
|
330
320
|
}
|
|
331
321
|
else {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
322
|
+
// 覆盖以target为准
|
|
323
|
+
iteratorTarget = target;
|
|
324
|
+
}
|
|
325
|
+
for (const keyName in iteratorTarget) {
|
|
326
|
+
if (!isAdd && !(keyName in source)) {
|
|
327
|
+
// 仅替换 但是源端没有此键
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
const targetValue = Reflect.get(target, keyName);
|
|
331
|
+
const sourceValue = Reflect.get(source, keyName);
|
|
332
|
+
if (typeof sourceValue === "object" &&
|
|
333
|
+
sourceValue != null &&
|
|
334
|
+
keyName in target &&
|
|
335
|
+
!UtilsContext.isDOM(sourceValue)) {
|
|
336
|
+
// 源端的值是object类型,且不是元素节点
|
|
337
|
+
// 如果是数组,那此数组中有值,清空旧的数组再赋值
|
|
338
|
+
let childObjectValue;
|
|
339
|
+
if (Array.isArray(sourceValue)) {
|
|
340
|
+
if (Array.isArray(targetValue)) {
|
|
341
|
+
targetValue.length = 0;
|
|
343
342
|
}
|
|
344
|
-
|
|
345
|
-
Reflect.set(target, targetKeyName, sourceValue);
|
|
343
|
+
childObjectValue = sourceValue;
|
|
346
344
|
}
|
|
345
|
+
else {
|
|
346
|
+
childObjectValue = UtilsContext.assign(targetValue, sourceValue, isAdd);
|
|
347
|
+
}
|
|
348
|
+
Reflect.set(target, keyName, childObjectValue);
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
/* 直接赋值 */
|
|
352
|
+
Reflect.set(target, keyName, sourceValue);
|
|
347
353
|
}
|
|
348
354
|
}
|
|
349
355
|
return target;
|
|
@@ -440,6 +446,9 @@ class CommonUtil {
|
|
|
440
446
|
}
|
|
441
447
|
toJSON(data, errorCallBack) {
|
|
442
448
|
let result = {};
|
|
449
|
+
if (data == null) {
|
|
450
|
+
return result;
|
|
451
|
+
}
|
|
443
452
|
if (typeof data === "object") {
|
|
444
453
|
return data;
|
|
445
454
|
}
|
|
@@ -5492,7 +5501,7 @@ class DOMUtils {
|
|
|
5492
5501
|
}
|
|
5493
5502
|
const domUtils = new DOMUtils();
|
|
5494
5503
|
|
|
5495
|
-
const version = "2.9.
|
|
5504
|
+
const version = "2.9.8";
|
|
5496
5505
|
|
|
5497
5506
|
class Utils {
|
|
5498
5507
|
windowApi;
|
|
@@ -8030,7 +8039,7 @@ class Utils {
|
|
|
8030
8039
|
}
|
|
8031
8040
|
}
|
|
8032
8041
|
/**
|
|
8033
|
-
*
|
|
8042
|
+
* 深度获取对象的某个属性
|
|
8034
8043
|
* @param target 待获取的对象
|
|
8035
8044
|
* @param handler 获取属性的回调
|
|
8036
8045
|
*/
|