@reldens/utils 0.4.6 → 0.10.0-beta.2
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 +13 -4
- package/package.json +1 -1
package/lib/shortcuts.js
CHANGED
|
@@ -23,9 +23,9 @@ class Shortcuts
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
isTrue(obj, prop)
|
|
26
|
+
isTrue(obj, prop, strictValidation)
|
|
27
27
|
{
|
|
28
|
-
return (obj && {}.hasOwnProperty.call(obj, prop) && obj[prop]);
|
|
28
|
+
return (obj && {}.hasOwnProperty.call(obj, prop) && (strictValidation ? true === obj[prop] : obj[prop]));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
isArray(obj)
|
|
@@ -33,6 +33,15 @@ class Shortcuts
|
|
|
33
33
|
return Array.isArray(obj);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
convertArrayToObjectByKeys(dataArray, keyProperty)
|
|
37
|
+
{
|
|
38
|
+
let objectByKeys = {};
|
|
39
|
+
for(let arrayItem of dataArray){
|
|
40
|
+
objectByKeys[arrayItem[keyProperty]] = arrayItem;
|
|
41
|
+
}
|
|
42
|
+
return objectByKeys;
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
sortObjectKeysBy(object, sortField)
|
|
37
46
|
{
|
|
38
47
|
return Object.keys(object).sort((a,b) => {
|
|
@@ -48,7 +57,7 @@ class Shortcuts
|
|
|
48
57
|
return to;
|
|
49
58
|
}
|
|
50
59
|
|
|
51
|
-
|
|
60
|
+
toJson(jsonString, defaultReturn = false)
|
|
52
61
|
{
|
|
53
62
|
return this.parseJson(jsonString) || defaultReturn;
|
|
54
63
|
}
|
|
@@ -62,7 +71,7 @@ class Shortcuts
|
|
|
62
71
|
}
|
|
63
72
|
}
|
|
64
73
|
|
|
65
|
-
|
|
74
|
+
get(object, prop, defaultReturn)
|
|
66
75
|
{
|
|
67
76
|
return this.hasOwn(object, prop) ? object[prop] : defaultReturn;
|
|
68
77
|
}
|