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