@reldens/utils 0.11.0 → 0.12.0
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/lib/shortcuts.js +19 -3
- package/package.json +1 -1
package/lib/shortcuts.js
CHANGED
|
@@ -11,16 +11,15 @@ class Shortcuts
|
|
|
11
11
|
|
|
12
12
|
hasOwn(obj, prop)
|
|
13
13
|
{
|
|
14
|
-
if(this.isArray(prop)){
|
|
14
|
+
if(this.isArray(prop) && 0 < prop.length){
|
|
15
15
|
for(let value of prop){
|
|
16
16
|
if(!(obj && {}.hasOwnProperty.call(obj, value))){
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
return true;
|
|
21
|
-
} else {
|
|
22
|
-
return (obj && {}.hasOwnProperty.call(obj, prop));
|
|
23
21
|
}
|
|
22
|
+
return (obj && {}.hasOwnProperty.call(obj, prop));
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
isTrue(obj, prop, strictValidation)
|
|
@@ -33,8 +32,19 @@ class Shortcuts
|
|
|
33
32
|
return Array.isArray(obj);
|
|
34
33
|
}
|
|
35
34
|
|
|
35
|
+
length(obj)
|
|
36
|
+
{
|
|
37
|
+
if(!obj){
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
return Object.keys(obj).length;
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
convertObjectsArrayToObjectByKeys(dataArray, keyProperty)
|
|
37
44
|
{
|
|
45
|
+
if(!this.isArray(dataArray) || 0 === dataArray.length){
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
38
48
|
let objectByKeys = {};
|
|
39
49
|
for(let arrayItem of dataArray){
|
|
40
50
|
objectByKeys[arrayItem[keyProperty]] = arrayItem;
|
|
@@ -51,6 +61,9 @@ class Shortcuts
|
|
|
51
61
|
|
|
52
62
|
propsAssign(from, to, props)
|
|
53
63
|
{
|
|
64
|
+
if(!this.isArray(props)){
|
|
65
|
+
return to;
|
|
66
|
+
}
|
|
54
67
|
for(let i of props){
|
|
55
68
|
to[i] = from[i];
|
|
56
69
|
}
|
|
@@ -91,6 +104,9 @@ class Shortcuts
|
|
|
91
104
|
|
|
92
105
|
serializeFormData(formData)
|
|
93
106
|
{
|
|
107
|
+
if(0 === formData.length){
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
94
110
|
let obj = {};
|
|
95
111
|
for(let [key, value] of formData){
|
|
96
112
|
if(obj[key] !== undefined){
|