@kizmann/pico-js 0.3.21 → 0.3.24

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizmann/pico-js",
3
- "version": "0.3.21",
3
+ "version": "0.3.24",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "author": "Eduard Kizmann <kizmann@protonmail.ch>",
@@ -726,8 +726,12 @@ export class Dom
726
726
  }
727
727
  }
728
728
 
729
- value(val)
729
+ value(val = undefined)
730
730
  {
731
+ if ( val === undefined ) {
732
+ return this.get(0).value;
733
+ }
734
+
731
735
  this.each((el) => el.value = val);
732
736
 
733
737
  return this;
@@ -20,7 +20,7 @@ export class Obj
20
20
  }
21
21
 
22
22
  if ( keys === null || keys === undefined ) {
23
- return obj;
23
+ return fallback;
24
24
  }
25
25
 
26
26
  if ( Any.isArray(keys) ) {
@@ -35,11 +35,15 @@ export class Obj
35
35
 
36
36
  let index = 0, length = keys.length;
37
37
 
38
- while (obj !== undefined && index < length) {
38
+ if ( length === 0 ) {
39
+ return fallback;
40
+ }
41
+
42
+ while (obj !== undefined && obj !== null && index < length) {
39
43
  obj = obj[keys[index++]];
40
44
  }
41
45
 
42
- if ( typeof obj === 'undefined' ) {
46
+ if ( obj === undefined || obj === null) {
43
47
  return fallback;
44
48
  }
45
49
 
@@ -48,26 +52,49 @@ export class Obj
48
52
 
49
53
  static set(obj, keys, val)
50
54
  {
51
- keys = (typeof keys === 'string' && keys.match(/^[^\.]+(\.[^\.]+)*$/)) ?
52
- keys.split('.') : keys;
55
+ if ( Any.isArray(keys) ) {
56
+ keys = keys.join('.');
57
+ }
53
58
 
54
- let key = keys.shift();
59
+ if ( ! Any.isString(keys) ) {
60
+ keys = keys.toString();
61
+ }
55
62
 
56
- if ( obj[key] === undefined || obj[key] === null ) {
57
- obj[key] = {};
63
+ keys = keys.split('.');
64
+
65
+ let index = 0, length = keys.length, nested = obj;
66
+
67
+ if ( length === 0 ) {
68
+ return obj;
58
69
  }
59
70
 
60
- if ( keys.length === 0 ) {
61
- return obj[key] = val;
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++]];
62
82
  }
63
83
 
64
- return this.set(obj[key], keys, val);
84
+ return obj;
65
85
  }
66
86
 
67
87
  static unset(obj, keys)
68
88
  {
69
- keys = (typeof keys === 'string' && keys.match(/^[^\.]+(\.[^\.]+)*$/)) ?
70
- keys.split('.') : 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('.');
71
98
 
72
99
  let key = keys.shift();
73
100