@kizmann/pico-js 0.3.29 → 0.3.31

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/docs/cookie.html CHANGED
@@ -29,6 +29,7 @@
29
29
  'use strict';
30
30
 
31
31
  pi.Dom.ready(function() {
32
+ console.log(pi.Str.real('[1,"foo",3]'));
32
33
  pi.Cookie.set('foobar1', { foo: 'bar', pi: { nano: 'ui', kyoto: 'cms' } });
33
34
  console.log(pi.Cookie.get('foobar1', {}, 'object'));
34
35
  pi.Cookie.set('foobar2', ['foo', 'bar', 1], 60 * 60);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizmann/pico-js",
3
- "version": "0.3.29",
3
+ "version": "0.3.31",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "author": "Eduard Kizmann <kizmann@protonmail.ch>",
@@ -27,8 +27,11 @@ export class Obj
27
27
  keys = keys.join('.');
28
28
  }
29
29
 
30
- let undef = typeof obj === 'object' && (obj[keys] === null ||
31
- obj[keys] === undefined);
30
+ let undef = true;
31
+
32
+ if ( typeof obj === 'object' ) {
33
+ undef = obj[keys] === null || obj[keys] === undefined
34
+ }
32
35
 
33
36
  if ( ! undef ) {
34
37
  return obj[keys];
@@ -67,8 +70,11 @@ export class Obj
67
70
  keys = keys.toString();
68
71
  }
69
72
 
70
- let undef = typeof obj === 'object' && (obj[keys] !== null ||
71
- obj[keys] !== undefined);
73
+ let undef = true;
74
+
75
+ if ( typeof obj === 'object' ) {
76
+ undef = obj[keys] === null || obj[keys] === undefined
77
+ }
72
78
 
73
79
  if ( ! undef ) {
74
80
  obj[keys] = val; return obj;
@@ -107,8 +107,25 @@ export class Str
107
107
  return size;
108
108
  }
109
109
 
110
+ static array(value, fallback = null)
111
+ {
112
+ let matches = value.match(/((?<=(\[|,))(.*?)(?=(,|\])))+/g);
113
+
114
+ if ( ! Any.isArray(matches) ) {
115
+ return fallback;
116
+ }
117
+
118
+ return Arr.each(matches, (value) => {
119
+ return Str.real(value.replace(/(^"|^'|"$|'$)/g, ''));
120
+ });
121
+ }
122
+
110
123
  static real(value)
111
124
  {
125
+ if ( typeof value === 'string' && value.match(/^\[.*?\]$/) ) {
126
+ value = Str.array(value);
127
+ }
128
+
112
129
  if ( typeof value === 'string' && value.match(/^(null)$/i) ) {
113
130
  value = null;
114
131
  }