@kizmann/pico-js 0.3.19 → 0.3.22
Sign up to get free protection for your applications and to get access to all the features.
- 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 -23
package/package.json
CHANGED
package/src/utility/object.js
CHANGED
@@ -19,54 +19,82 @@ export class Obj
|
|
19
19
|
return fallback;
|
20
20
|
}
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
if ( keys === null || keys === undefined ) {
|
23
|
+
return fallback;
|
24
|
+
}
|
24
25
|
|
25
|
-
if ( Any.isArray(keys)
|
26
|
-
keys =
|
26
|
+
if ( Any.isArray(keys) ) {
|
27
|
+
keys = keys.join('.');
|
27
28
|
}
|
28
29
|
|
29
|
-
|
30
|
+
if ( ! Any.isString(keys) ) {
|
31
|
+
keys = keys.toString();
|
32
|
+
}
|
30
33
|
|
31
|
-
|
32
|
-
result = result.concat(key.split('.'))
|
33
|
-
});
|
34
|
+
keys = keys.split('.');
|
34
35
|
|
35
|
-
let
|
36
|
+
let index = 0, length = keys.length;
|
36
37
|
|
37
|
-
if (
|
38
|
+
if ( length === 0 ) {
|
38
39
|
return fallback;
|
39
40
|
}
|
40
41
|
|
41
|
-
|
42
|
-
|
42
|
+
while (obj !== undefined && index < length) {
|
43
|
+
obj = obj[keys[index++]];
|
43
44
|
}
|
44
45
|
|
45
|
-
|
46
|
+
if ( typeof obj === 'undefined' ) {
|
47
|
+
return fallback;
|
48
|
+
}
|
49
|
+
|
50
|
+
return obj;
|
46
51
|
}
|
47
52
|
|
48
53
|
static set(obj, keys, val)
|
49
54
|
{
|
50
|
-
|
51
|
-
keys.
|
55
|
+
if ( Any.isArray(keys) ) {
|
56
|
+
keys = keys.join('.');
|
57
|
+
}
|
52
58
|
|
53
|
-
|
59
|
+
if ( ! Any.isString(keys) ) {
|
60
|
+
keys = keys.toString();
|
61
|
+
}
|
54
62
|
|
55
|
-
|
56
|
-
|
63
|
+
keys = keys.split('.');
|
64
|
+
|
65
|
+
let index = 0, length = keys.length, nested = obj;
|
66
|
+
|
67
|
+
if ( length === 0 ) {
|
68
|
+
return obj;
|
57
69
|
}
|
58
70
|
|
59
|
-
|
60
|
-
|
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++]];
|
61
82
|
}
|
62
83
|
|
63
|
-
return
|
84
|
+
return obj;
|
64
85
|
}
|
65
86
|
|
66
87
|
static unset(obj, keys)
|
67
88
|
{
|
68
|
-
|
69
|
-
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('.');
|
70
98
|
|
71
99
|
let key = keys.shift();
|
72
100
|
|