@kizmann/pico-js 0.3.20 → 0.3.23
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/pico-js.js +1 -1
- package/dist/pico-js.js.map +1 -1
- package/package.json +1 -1
- package/src/utility/object.js +51 -31
package/package.json
CHANGED
package/src/utility/object.js
CHANGED
@@ -19,62 +19,82 @@ export class Obj
|
|
19
19
|
return fallback;
|
20
20
|
}
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
if ( Any.isArray(keys) === false ) {
|
26
|
-
keys = [keys];
|
22
|
+
if ( keys === null || keys === undefined ) {
|
23
|
+
return fallback;
|
27
24
|
}
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
key = (typeof key === 'string' && key.match(/^[^\.]+(\.[^\.]+)*$/)) ?
|
34
|
-
key.split('.') : key;
|
26
|
+
if ( Any.isArray(keys) ) {
|
27
|
+
keys = keys.join('.');
|
28
|
+
}
|
35
29
|
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
if ( ! Any.isString(keys) ) {
|
31
|
+
keys = keys.toString();
|
32
|
+
}
|
39
33
|
|
40
|
-
|
41
|
-
});
|
34
|
+
keys = keys.split('.');
|
42
35
|
|
43
|
-
let
|
36
|
+
let index = 0, length = keys.length;
|
44
37
|
|
45
|
-
if (
|
38
|
+
if ( length === 0 ) {
|
46
39
|
return fallback;
|
47
40
|
}
|
48
41
|
|
49
|
-
|
50
|
-
|
42
|
+
while (obj !== undefined && obj !== null && index < length) {
|
43
|
+
obj = obj[keys[index++]];
|
44
|
+
}
|
45
|
+
|
46
|
+
if ( obj === undefined || obj === null) {
|
47
|
+
return fallback;
|
51
48
|
}
|
52
49
|
|
53
|
-
return
|
50
|
+
return obj;
|
54
51
|
}
|
55
52
|
|
56
53
|
static set(obj, keys, val)
|
57
54
|
{
|
58
|
-
|
59
|
-
keys.
|
55
|
+
if ( Any.isArray(keys) ) {
|
56
|
+
keys = keys.join('.');
|
57
|
+
}
|
60
58
|
|
61
|
-
|
59
|
+
if ( ! Any.isString(keys) ) {
|
60
|
+
keys = keys.toString();
|
61
|
+
}
|
62
|
+
|
63
|
+
keys = keys.split('.');
|
64
|
+
|
65
|
+
let index = 0, length = keys.length, nested = obj;
|
62
66
|
|
63
|
-
if (
|
64
|
-
obj
|
67
|
+
if ( length === 0 ) {
|
68
|
+
return obj;
|
65
69
|
}
|
66
70
|
|
67
|
-
|
68
|
-
|
71
|
+
while (nested !== null && index < length) {
|
72
|
+
|
73
|
+
if ( nested[keys[index]] === undefined || nested[keys[index]] === null ) {
|
74
|
+
nested[keys[index]] = {};
|
75
|
+
}
|
76
|
+
|
77
|
+
if ( index == length - 1 ) {
|
78
|
+
nested[keys[index]] = val;
|
79
|
+
}
|
80
|
+
|
81
|
+
nested = nested[keys[index++]];
|
69
82
|
}
|
70
83
|
|
71
|
-
return
|
84
|
+
return obj;
|
72
85
|
}
|
73
86
|
|
74
87
|
static unset(obj, keys)
|
75
88
|
{
|
76
|
-
|
77
|
-
keys.
|
89
|
+
if ( Any.isArray(keys) ) {
|
90
|
+
keys = keys.join('.');
|
91
|
+
}
|
92
|
+
|
93
|
+
if ( ! Any.isString(keys) ) {
|
94
|
+
keys = keys.toString();
|
95
|
+
}
|
96
|
+
|
97
|
+
keys = keys.split('.');
|
78
98
|
|
79
99
|
let key = keys.shift();
|
80
100
|
|