@kizmann/pico-js 0.3.30 → 0.3.32
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/pico-js.js +1 -1
- package/dist/pico-js.js.map +1 -1
- package/docs/cookie.html +1 -0
- package/package.json +1 -1
- package/src/utility/string.js +18 -1
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
package/src/utility/string.js
CHANGED
@@ -107,9 +107,26 @@ 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
|
{
|
112
|
-
if ( typeof value === 'string' && value.match(
|
125
|
+
if ( typeof value === 'string' && value.match(/^@\[.*?\]$/) ) {
|
126
|
+
value = Str.array(value);
|
127
|
+
}
|
128
|
+
|
129
|
+
if ( typeof value === 'string' && value.match(/^(null|undefined)$/i) ) {
|
113
130
|
value = null;
|
114
131
|
}
|
115
132
|
|