@whitesev/utils 2.9.5 → 2.9.7

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.
@@ -82,6 +82,9 @@ System.register('Utils', [], (function (exports) {
82
82
  if (typeof level !== "number") {
83
83
  level = Number(level);
84
84
  }
85
+ if (isNaN(level)) {
86
+ throw new TypeError(`输入错误的level:${level}`);
87
+ }
85
88
  const rgbc = this.hexToRgb(color);
86
89
  for (let index = 0; index < 3; index++) {
87
90
  const rgbcItemValue = rgbc[index];
@@ -102,6 +105,9 @@ System.register('Utils', [], (function (exports) {
102
105
  if (typeof level !== "number") {
103
106
  level = Number(level);
104
107
  }
108
+ if (isNaN(level)) {
109
+ throw new TypeError(`输入错误的level:${level}`);
110
+ }
105
111
  const rgbc = this.hexToRgb(color);
106
112
  for (let index = 0; index < 3; index++) {
107
113
  const rgbcItemValue = Number(rgbc[index]);
@@ -309,38 +315,44 @@ System.register('Utils', [], (function (exports) {
309
315
  if (target == null) {
310
316
  target = {};
311
317
  }
318
+ // 当前遍历的目标对象
319
+ let iteratorTarget;
312
320
  if (isAdd) {
313
- for (const sourceKeyName in source) {
314
- const targetKeyName = sourceKeyName;
315
- const targetValue = Reflect.get(target, targetKeyName);
316
- const sourceValue = Reflect.get(source, sourceKeyName);
317
- if (typeof sourceValue === "object" &&
318
- sourceValue != null &&
319
- sourceKeyName in target &&
320
- !UtilsContext.isDOM(sourceValue)) {
321
- /* 源端的值是object类型,且不是元素节点 */
322
- Reflect.set(target, sourceKeyName, UtilsContext.assign(targetValue, sourceValue, isAdd));
323
- continue;
324
- }
325
- Reflect.set(target, sourceKeyName, sourceValue);
326
- }
321
+ // 追加并覆盖是以source为准
322
+ iteratorTarget = source;
327
323
  }
328
324
  else {
329
- for (const targetKeyName in target) {
330
- if (targetKeyName in source) {
331
- const targetValue = Reflect.get(target, targetKeyName);
332
- const sourceValue = Reflect.get(source, targetKeyName);
333
- if (typeof sourceValue === "object" &&
334
- sourceValue != null &&
335
- !UtilsContext.isDOM(sourceValue) &&
336
- Object.keys(sourceValue).length) {
337
- /* 源端的值是object类型,且不是元素节点 */
338
- Reflect.set(target, targetKeyName, UtilsContext.assign(targetValue, sourceValue, isAdd));
339
- continue;
325
+ // 覆盖以target为准
326
+ iteratorTarget = target;
327
+ }
328
+ for (const keyName in iteratorTarget) {
329
+ if (!isAdd && !(keyName in source)) {
330
+ // 仅替换 但是源端没有此键
331
+ continue;
332
+ }
333
+ const targetValue = Reflect.get(target, keyName);
334
+ const sourceValue = Reflect.get(source, keyName);
335
+ if (typeof sourceValue === "object" &&
336
+ sourceValue != null &&
337
+ keyName in target &&
338
+ !UtilsContext.isDOM(sourceValue)) {
339
+ // 源端的值是object类型,且不是元素节点
340
+ // 如果是数组,那此数组中有值,清空旧的数组再赋值
341
+ let childObjectValue;
342
+ if (Array.isArray(sourceValue)) {
343
+ if (Array.isArray(targetValue)) {
344
+ targetValue.length = 0;
340
345
  }
341
- /* 直接赋值 */
342
- Reflect.set(target, targetKeyName, sourceValue);
346
+ childObjectValue = sourceValue;
347
+ }
348
+ else {
349
+ childObjectValue = UtilsContext.assign(targetValue, sourceValue, isAdd);
343
350
  }
351
+ Reflect.set(target, keyName, childObjectValue);
352
+ }
353
+ else {
354
+ /* 直接赋值 */
355
+ Reflect.set(target, keyName, sourceValue);
344
356
  }
345
357
  }
346
358
  return target;
@@ -585,7 +597,7 @@ System.register('Utils', [], (function (exports) {
585
597
  }
586
598
  }
587
599
  /**
588
- * 获取多组Cookie
600
+ * 获取多组Cookie
589
601
  * @param option 配置
590
602
  **/
591
603
  getList(option) {
@@ -698,7 +710,8 @@ System.register('Utils', [], (function (exports) {
698
710
  }
699
711
  }
700
712
  /**
701
- * 解析cookie字符串
713
+ * 解析cookie字符串,按`;`分割
714
+ *
702
715
  * 例如:document.cookie
703
716
  * @param cookieStr
704
717
  */
@@ -2115,31 +2128,31 @@ System.register('Utils', [], (function (exports) {
2115
2128
  }
2116
2129
  /**
2117
2130
  * 设置当enable为true时默认显示在菜单中前面的emoji图标
2118
- * @param emojiString
2131
+ * @param emojiString emoji字符串
2119
2132
  */
2120
2133
  setEnableTrueEmoji(emojiString) {
2121
2134
  if (typeof emojiString !== "string") {
2122
- throw new Error("参数emojiString必须是string类型");
2135
+ throw new TypeError("参数emojiString必须是string类型");
2123
2136
  }
2124
2137
  this.MenuHandle.$emoji.success = emojiString;
2125
2138
  }
2126
2139
  /**
2127
2140
  * 设置当enable为false时默认显示在菜单中前面的emoji图标
2128
- * @param emojiString
2141
+ * @param emojiString emoji字符串
2129
2142
  */
2130
2143
  setEnableFalseEmoji(emojiString) {
2131
2144
  if (typeof emojiString !== "string") {
2132
- throw new Error("参数emojiString必须是string类型");
2145
+ throw new TypeError("参数emojiString必须是string类型");
2133
2146
  }
2134
2147
  this.MenuHandle.$emoji.error = emojiString;
2135
2148
  }
2136
2149
  /**
2137
2150
  * 设置本地存储的菜单外部的键名
2138
- * @param keyName
2151
+ * @param keyName 键名
2139
2152
  */
2140
2153
  setLocalStorageKeyName(keyName) {
2141
2154
  if (typeof keyName !== "string") {
2142
- throw new Error("参数keyName必须是string类型");
2155
+ throw new TypeError("参数keyName必须是string类型");
2143
2156
  }
2144
2157
  this.MenuHandle.$data.key = keyName;
2145
2158
  }
@@ -5488,7 +5501,7 @@ System.register('Utils', [], (function (exports) {
5488
5501
  }
5489
5502
  const domUtils = new DOMUtils();
5490
5503
 
5491
- const version = "2.9.5";
5504
+ const version = "2.9.7";
5492
5505
 
5493
5506
  class Utils {
5494
5507
  windowApi;