yuang-framework-ui-common 1.0.33 → 1.0.35

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.
@@ -1,5 +1,45 @@
1
- import { cloneDeep } from 'lodash';
1
+
2
+ /**
3
+ * 浅度克隆对象
4
+ * @param obj
5
+ * @returns {{}|*}
6
+ */
7
+ const shallowClone = (obj) => {
8
+ return Object.assign({}, obj);
9
+ }
10
+
11
+
12
+ /**
13
+ * 深度克隆对象
14
+ * @param obj
15
+ * @returns {{}|*}
16
+ */
17
+ const deepClone = (obj) => {
18
+ let result;
19
+ const type = typeOf(obj);
20
+ if (type === 'Object') result = {};
21
+ else if (type === 'Array') result = [];
22
+ else return obj;
23
+ Object.keys(obj).forEach(key => {
24
+ const copy = obj[key], cType = typeOf(copy);
25
+ if (cType === 'Object' || cType === 'Array') result[key] = deepClone(copy);
26
+ else result[key] = obj[key];
27
+ });
28
+ return result;
29
+ }
30
+ /**
31
+ * 获取变量类型
32
+ * @param obj
33
+ * @returns {string}
34
+ */
35
+ const typeOf = (obj) => {
36
+ if (obj === null) return 'Null';
37
+ if (obj === undefined) return 'Undefined';
38
+ return Object.prototype.toString.call(obj).slice(8, -1);
39
+ };
2
40
 
3
41
  export {
4
- cloneDeep
42
+ shallowClone,
43
+ deepClone,
44
+ typeOf,
5
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuang-framework-ui-common",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {