@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.umd.js
CHANGED
|
@@ -316,38 +316,44 @@
|
|
|
316
316
|
if (target == null) {
|
|
317
317
|
target = {};
|
|
318
318
|
}
|
|
319
|
+
// 当前遍历的目标对象
|
|
320
|
+
let iteratorTarget;
|
|
319
321
|
if (isAdd) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const targetValue = Reflect.get(target, targetKeyName);
|
|
323
|
-
const sourceValue = Reflect.get(source, sourceKeyName);
|
|
324
|
-
if (typeof sourceValue === "object" &&
|
|
325
|
-
sourceValue != null &&
|
|
326
|
-
sourceKeyName in target &&
|
|
327
|
-
!UtilsContext.isDOM(sourceValue)) {
|
|
328
|
-
/* 源端的值是object类型,且不是元素节点 */
|
|
329
|
-
Reflect.set(target, sourceKeyName, UtilsContext.assign(targetValue, sourceValue, isAdd));
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
Reflect.set(target, sourceKeyName, sourceValue);
|
|
333
|
-
}
|
|
322
|
+
// 追加并覆盖是以source为准
|
|
323
|
+
iteratorTarget = source;
|
|
334
324
|
}
|
|
335
325
|
else {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
326
|
+
// 覆盖以target为准
|
|
327
|
+
iteratorTarget = target;
|
|
328
|
+
}
|
|
329
|
+
for (const keyName in iteratorTarget) {
|
|
330
|
+
if (!isAdd && !(keyName in source)) {
|
|
331
|
+
// 仅替换 但是源端没有此键
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
const targetValue = Reflect.get(target, keyName);
|
|
335
|
+
const sourceValue = Reflect.get(source, keyName);
|
|
336
|
+
if (typeof sourceValue === "object" &&
|
|
337
|
+
sourceValue != null &&
|
|
338
|
+
keyName in target &&
|
|
339
|
+
!UtilsContext.isDOM(sourceValue)) {
|
|
340
|
+
// 源端的值是object类型,且不是元素节点
|
|
341
|
+
// 如果是数组,那此数组中有值,清空旧的数组再赋值
|
|
342
|
+
let childObjectValue;
|
|
343
|
+
if (Array.isArray(sourceValue)) {
|
|
344
|
+
if (Array.isArray(targetValue)) {
|
|
345
|
+
targetValue.length = 0;
|
|
347
346
|
}
|
|
348
|
-
|
|
349
|
-
Reflect.set(target, targetKeyName, sourceValue);
|
|
347
|
+
childObjectValue = sourceValue;
|
|
350
348
|
}
|
|
349
|
+
else {
|
|
350
|
+
childObjectValue = UtilsContext.assign(targetValue, sourceValue, isAdd);
|
|
351
|
+
}
|
|
352
|
+
Reflect.set(target, keyName, childObjectValue);
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
/* 直接赋值 */
|
|
356
|
+
Reflect.set(target, keyName, sourceValue);
|
|
351
357
|
}
|
|
352
358
|
}
|
|
353
359
|
return target;
|
|
@@ -444,6 +450,9 @@
|
|
|
444
450
|
}
|
|
445
451
|
toJSON(data, errorCallBack) {
|
|
446
452
|
let result = {};
|
|
453
|
+
if (data == null) {
|
|
454
|
+
return result;
|
|
455
|
+
}
|
|
447
456
|
if (typeof data === "object") {
|
|
448
457
|
return data;
|
|
449
458
|
}
|
|
@@ -5496,7 +5505,7 @@
|
|
|
5496
5505
|
}
|
|
5497
5506
|
const domUtils = new DOMUtils();
|
|
5498
5507
|
|
|
5499
|
-
const version = "2.9.
|
|
5508
|
+
const version = "2.9.8";
|
|
5500
5509
|
|
|
5501
5510
|
class Utils {
|
|
5502
5511
|
windowApi;
|
|
@@ -8034,7 +8043,7 @@
|
|
|
8034
8043
|
}
|
|
8035
8044
|
}
|
|
8036
8045
|
/**
|
|
8037
|
-
*
|
|
8046
|
+
* 深度获取对象的某个属性
|
|
8038
8047
|
* @param target 待获取的对象
|
|
8039
8048
|
* @param handler 获取属性的回调
|
|
8040
8049
|
*/
|