@kizmann/pico-js 0.3.18 → 0.3.21

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.18",
3
+ "version": "0.3.21",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "author": "Eduard Kizmann <kizmann@protonmail.ch>",
@@ -19,24 +19,31 @@ export class Obj
19
19
  return fallback;
20
20
  }
21
21
 
22
- keys = (typeof keys === 'string' && keys.match(/^[^\.]+(\.[^\.]+)*$/)) ?
23
- keys.split('.') : keys;
22
+ if ( keys === null || keys === undefined ) {
23
+ return obj;
24
+ }
24
25
 
25
- if ( Any.isArray(keys) === false ) {
26
- keys = [keys];
26
+ if ( Any.isArray(keys) ) {
27
+ keys = keys.join('.');
27
28
  }
28
29
 
29
- let key = keys.shift();
30
+ if ( ! Any.isString(keys) ) {
31
+ keys = keys.toString();
32
+ }
30
33
 
31
- if ( typeof obj[key] === 'undefined' ) {
32
- return fallback;
34
+ keys = keys.split('.');
35
+
36
+ let index = 0, length = keys.length;
37
+
38
+ while (obj !== undefined && index < length) {
39
+ obj = obj[keys[index++]];
33
40
  }
34
41
 
35
- if ( keys.length === 0 ) {
36
- return obj[key];
42
+ if ( typeof obj === 'undefined' ) {
43
+ return fallback;
37
44
  }
38
45
 
39
- return this.get(obj[key], keys, fallback)
46
+ return obj;
40
47
  }
41
48
 
42
49
  static set(obj, keys, val)
@@ -86,7 +93,7 @@ export class Obj
86
93
  }
87
94
  });
88
95
 
89
- if ( ! Any.isEmpty(assign) ) {
96
+ if ( !Any.isEmpty(assign) ) {
90
97
  result = this.assign(result, assign);
91
98
  }
92
99
 
@@ -103,7 +110,7 @@ export class Obj
103
110
  }
104
111
  });
105
112
 
106
- if ( ! Any.isEmpty(assign) ) {
113
+ if ( !Any.isEmpty(assign) ) {
107
114
  result = this.assign(result, assign);
108
115
  }
109
116
 
@@ -148,7 +155,7 @@ export class Obj
148
155
  });
149
156
  }
150
157
 
151
- if ( ! Any.isFunction(key) ) {
158
+ if ( !Any.isFunction(key) ) {
152
159
  keys = keys.sort((a, b) => {
153
160
  return Any.integer(Obj.get(obj[a], key)) - Any.integer(Obj.get(obj[b], key));
154
161
  })
@@ -168,13 +175,13 @@ export class Obj
168
175
  {
169
176
  let keys = Any.keys(obj);
170
177
 
171
- if ( ! Any.isFunction(key) ) {
178
+ if ( !Any.isFunction(key) ) {
172
179
  keys = keys.sort((a, b) => {
173
180
 
174
181
  let va = Any.string(Obj.get(obj[a], key)).toLowerCase();
175
182
  let vb = Any.string(Obj.get(obj[b], key)).toLowerCase();
176
183
 
177
- return(va < vb) ? -1 : (va > vb) ? 1 : 0;
184
+ return (va < vb) ? - 1 : (va > vb) ? 1 : 0;
178
185
  })
179
186
  }
180
187
 
@@ -265,8 +272,7 @@ export class Obj
265
272
 
266
273
  if ( obj instanceof FormData ) {
267
274
 
268
- for (let [key, value] of obj.entries())
269
- {
275
+ for ( let [key, value] of obj.entries() ) {
270
276
  result[key] = callback(value, key);
271
277
  }
272
278