@kizmann/pico-js 0.3.35 → 0.3.36

Sign up to get free protection for your applications and to get access to all the features.
package/docs/cookie.html CHANGED
@@ -29,6 +29,13 @@
29
29
  'use strict';
30
30
 
31
31
  pi.Dom.ready(function() {
32
+
33
+ var obj = {
34
+ foo: { bar: 'key' }, hu: 'tem', ka: { se: { nope: 'lol' } }
35
+ };
36
+
37
+ console.log(pi.Obj.flatten(obj));
38
+
32
39
  console.log(pi.Str.real('@[\'\']'));
33
40
  console.log(pi.Str.real('@[1,"foo",3]'));
34
41
  pi.Cookie.set('foobar1', { foo: 'bar', pi: { nano: 'ui', kyoto: 'cms' } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizmann/pico-js",
3
- "version": "0.3.35",
3
+ "version": "0.3.36",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "author": "Eduard Kizmann <kizmann@protonmail.ch>",
@@ -379,6 +379,34 @@ export class Obj
379
379
  return result;
380
380
  }
381
381
 
382
+ static flatten(obj)
383
+ {
384
+ let result = {};
385
+
386
+ let callback = (val, sey = null) => {
387
+
388
+ Arr.each(Any.keys(val), (key) => {
389
+
390
+ let tey = key;
391
+
392
+ if ( ! Any.isEmpty(sey) ) {
393
+ tey = `${sey}.${key}`;
394
+ }
395
+
396
+ if ( Any.isPlain(val[key]) ) {
397
+ return callback(val[key], tey);
398
+ }
399
+
400
+ result[tey] = val[key];
401
+ });
402
+
403
+ };
404
+
405
+ callback(obj);
406
+
407
+ return result;
408
+ }
409
+
382
410
  }
383
411
 
384
412
  export default Obj;