@kizmann/pico-js 0.3.35 → 0.3.36
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/docs/cookie.html +7 -0
- package/package.json +1 -1
- package/src/utility/object.js +28 -0
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
package/src/utility/object.js
CHANGED
@@ -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;
|