@kizmann/pico-js 1.0.13 → 2.0.0
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/README.md +27 -7
- package/dist/pico-js.browser.js +2 -0
- package/dist/pico-js.browser.js.map +1 -0
- package/dist/pico-js.esm.js +2 -0
- package/dist/pico-js.esm.js.map +1 -0
- package/package.json +20 -7
- package/src/dom/DomAttribute.js +374 -0
- package/src/dom/DomBuilder.js +152 -0
- package/src/dom/DomEvent.js +253 -0
- package/src/dom/DomFinder.js +669 -0
- package/src/dom/DomForm.js +57 -0
- package/src/dom/DomGlobal.js +193 -0
- package/src/dom/DomInview.js +332 -0
- package/src/dom/DomMeta.js +66 -0
- package/src/dom/DomObserver.js +57 -0
- package/src/dom/DomRectangle.js +657 -0
- package/src/format/FormatFile.js +54 -0
- package/src/format/FormatOption.js +108 -0
- package/src/format/FormatParam.js +107 -0
- package/src/format/FormatParser.js +156 -0
- package/src/format/FormatUrl.js +75 -0
- package/src/index.browser.js +10 -0
- package/src/index.esm.js +138 -0
- package/src/now/NowDefault.js +533 -0
- package/src/now/NowFormat.js +196 -0
- package/src/now/NowGrid.js +251 -0
- package/src/now/NowHuman.js +118 -0
- package/src/now/NowMatch.js +175 -0
- package/src/now/NowRange.js +70 -0
- package/src/now/NowWalker.js +544 -0
- package/src/tool/scope.js +103 -0
- package/src/utils/Array.js +986 -0
- package/src/utils/Cookie.js +184 -0
- package/src/utils/Data.js +200 -0
- package/src/utils/Dom.js +208 -0
- package/src/utils/Event.js +140 -0
- package/src/utils/Format.js +62 -0
- package/src/utils/Hash.js +164 -0
- package/src/utils/Locale.js +229 -0
- package/src/utils/Mixed.js +887 -0
- package/src/utils/Now.js +234 -0
- package/src/utils/Number.js +238 -0
- package/src/utils/Object.js +655 -0
- package/src/utils/Route.js +67 -0
- package/src/utils/Runner.js +327 -0
- package/src/utils/String.js +618 -0
- package/src/{library/element.js → wip/Element.js} +90 -16
- package/src/{library/map.js → wip/Map.js} +256 -40
- package/types/dom/DomAttribute.d.ts +137 -0
- package/types/dom/DomBuilder.d.ts +67 -0
- package/types/dom/DomEvent.d.ts +103 -0
- package/types/dom/DomFinder.d.ts +321 -0
- package/types/dom/DomForm.d.ts +21 -0
- package/types/dom/DomGlobal.d.ts +79 -0
- package/types/dom/DomInview.d.ts +114 -0
- package/types/dom/DomMeta.d.ts +29 -0
- package/types/dom/DomObserver.d.ts +21 -0
- package/types/dom/DomRectangle.d.ts +270 -0
- package/types/format/FormatFile.d.ts +18 -0
- package/types/format/FormatOption.d.ts +40 -0
- package/types/format/FormatParam.d.ts +39 -0
- package/types/format/FormatParser.d.ts +46 -0
- package/types/format/FormatUrl.d.ts +17 -0
- package/types/index.browser.d.ts +1 -0
- package/types/index.esm.d.ts +52 -0
- package/types/now/NowDefault.d.ts +183 -0
- package/types/now/NowFormat.d.ts +70 -0
- package/types/now/NowGrid.d.ts +107 -0
- package/types/now/NowHuman.d.ts +37 -0
- package/types/now/NowMatch.d.ts +108 -0
- package/types/now/NowRange.d.ts +21 -0
- package/types/now/NowWalker.d.ts +301 -0
- package/types/tool/scope.d.ts +24 -0
- package/types/utils/Array.d.ts +480 -0
- package/types/utils/Cookie.d.ts +60 -0
- package/types/utils/Data.d.ts +91 -0
- package/types/utils/Dom.d.ts +138 -0
- package/types/utils/Event.d.ts +58 -0
- package/types/utils/Format.d.ts +37 -0
- package/types/utils/Hash.d.ts +81 -0
- package/types/utils/Locale.d.ts +115 -0
- package/types/utils/Mixed.d.ts +469 -0
- package/types/utils/Now.d.ts +125 -0
- package/types/utils/Number.d.ts +127 -0
- package/types/utils/Object.d.ts +255 -0
- package/types/utils/Route.d.ts +37 -0
- package/types/utils/Runner.d.ts +139 -0
- package/types/utils/String.d.ts +330 -0
- package/types/wip/Element.d.ts +119 -0
- package/types/wip/Map.d.ts +254 -0
- package/dist/.ignore.js +0 -0
- package/dist/pico-js.js +0 -2
- package/dist/pico-js.js.map +0 -1
- package/src/element/default.js +0 -46
- package/src/element/example.js +0 -58
- package/src/index.js +0 -90
- package/src/library/cookie.js +0 -123
- package/src/library/data.js +0 -111
- package/src/library/event.js +0 -91
- package/src/library/locale.js +0 -84
- package/src/library/queue.js +0 -64
- package/src/library/route.js +0 -28
- package/src/utility/any.js +0 -369
- package/src/utility/array.js +0 -410
- package/src/utility/dom.js +0 -1425
- package/src/utility/now.js +0 -544
- package/src/utility/number.js +0 -128
- package/src/utility/object.js +0 -429
- package/src/utility/string.js +0 -328
- package/types/index.d.ts +0 -77
- package/types/library/cookie.d.ts +0 -10
- package/types/library/data.d.ts +0 -15
- package/types/library/element.d.ts +0 -22
- package/types/library/event.d.ts +0 -13
- package/types/library/locale.d.ts +0 -14
- package/types/library/map.d.ts +0 -43
- package/types/library/queue.d.ts +0 -18
- package/types/library/route.d.ts +0 -11
- package/types/utility/any.d.ts +0 -35
- package/types/utility/array.d.ts +0 -46
- package/types/utility/dom.d.ts +0 -101
- package/types/utility/now.d.ts +0 -79
- package/types/utility/number.d.ts +0 -17
- package/types/utility/object.d.ts +0 -29
- package/types/utility/string.d.ts +0 -26
|
@@ -0,0 +1,887 @@
|
|
|
1
|
+
import { Arr, go, Mix, Run, Now, Locale, Str, Obj } from "#src/index.esm.js";
|
|
2
|
+
|
|
3
|
+
export const MIX_REGEX = {
|
|
4
|
+
'iso': /^\d{4}-\d{2}-\d{2}[T\s]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/,
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export class PicoMixed
|
|
8
|
+
{
|
|
9
|
+
/**
|
|
10
|
+
* Check if the value is empty
|
|
11
|
+
*
|
|
12
|
+
* @example Mix.isEmpty('') // => true
|
|
13
|
+
* @example Mix.isEmpty(null) // => true
|
|
14
|
+
* @example Mix.isEmpty([]) // => true
|
|
15
|
+
* @example Mix.isEmpty({}) // => true
|
|
16
|
+
* @example Mix.isEmpty(false) // => false
|
|
17
|
+
*
|
|
18
|
+
* @param {any} value The value to test
|
|
19
|
+
* @returns {boolean} Returns true if value is not empty
|
|
20
|
+
*/
|
|
21
|
+
static isEmpty(value)
|
|
22
|
+
{
|
|
23
|
+
if ( value == null ) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if ( typeof value === 'string' ) {
|
|
28
|
+
return value === '';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if ( typeof value === 'number' ) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if ( typeof value === 'boolean' ) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if ( this.isArr(value) ) {
|
|
40
|
+
return value.length === 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return this.len(value) === 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Check if the value is null
|
|
48
|
+
*
|
|
49
|
+
* @example Mix.isNull(null) // => true
|
|
50
|
+
* @example Mix.isNull(undefined) // => false
|
|
51
|
+
* @example Mix.isNull(0) // => false
|
|
52
|
+
* @example Mix.isNull('') // => false
|
|
53
|
+
*
|
|
54
|
+
* @param {any} value The value to test
|
|
55
|
+
* @returns {boolean} Return true if null
|
|
56
|
+
*/
|
|
57
|
+
static isNull(value)
|
|
58
|
+
{
|
|
59
|
+
return value === null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Check if the value is undefined
|
|
64
|
+
*
|
|
65
|
+
* @example Mix.isUndef(undefined) // => true
|
|
66
|
+
* @example Mix.isUndef(null) // => false
|
|
67
|
+
* @example Mix.isUndef(0) // => false
|
|
68
|
+
* @example Mix.isUndef('') // => false
|
|
69
|
+
*
|
|
70
|
+
* @param {any} value The value to test
|
|
71
|
+
* @returns {boolean} Return true if undefined
|
|
72
|
+
*/
|
|
73
|
+
static isUndef(value)
|
|
74
|
+
{
|
|
75
|
+
return value === undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Check if the value is null or undefined
|
|
80
|
+
*
|
|
81
|
+
* @example Mix.isNix(null) // => true
|
|
82
|
+
* @example Mix.isNix(undefined) // => true
|
|
83
|
+
* @example Mix.isNix(0) // => false
|
|
84
|
+
* @example Mix.isNix('') // => false
|
|
85
|
+
*
|
|
86
|
+
* @param {any} value The value to test
|
|
87
|
+
* @returns {boolean} Return true if null or undefined
|
|
88
|
+
*/
|
|
89
|
+
static isNix(value)
|
|
90
|
+
{
|
|
91
|
+
return value === undefined || value === null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Check if the value is string or number
|
|
96
|
+
*
|
|
97
|
+
* @example Mix.isPrim('foo') // => true
|
|
98
|
+
* @example Mix.isPrim(2.2) // => true
|
|
99
|
+
* @example Mix.isPrim([]) // => false
|
|
100
|
+
* @example Mix.isPrim(null) // => false
|
|
101
|
+
*
|
|
102
|
+
* @param {any} value The value to test
|
|
103
|
+
* @returns {boolean} Return true if typeof string or number
|
|
104
|
+
*/
|
|
105
|
+
static isPrim(value)
|
|
106
|
+
{
|
|
107
|
+
return typeof value === 'string' || typeof value === 'number';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @see PicoMixed.isPrim
|
|
112
|
+
*/
|
|
113
|
+
static isPrimitive = PicoMixed.isPrim;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Check if the value is a string
|
|
117
|
+
*
|
|
118
|
+
* @example Mix.isStr('foo') // => true
|
|
119
|
+
* @example Mix.isStr(1) // => false
|
|
120
|
+
*
|
|
121
|
+
* @param {any} value The value to test
|
|
122
|
+
* @returns {boolean} Return true if is string
|
|
123
|
+
*/
|
|
124
|
+
static isStr(value)
|
|
125
|
+
{
|
|
126
|
+
return typeof value === 'string';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @see PicoMixed.isStr
|
|
131
|
+
*/
|
|
132
|
+
static isString = PicoMixed.isStr;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Check if the value is a number
|
|
136
|
+
*
|
|
137
|
+
* @example Mix.isNum(12.2) // => true
|
|
138
|
+
* @example Mix.isNum('-4.3') // => true
|
|
139
|
+
* @example Mix.isNum('13f') // => false
|
|
140
|
+
*
|
|
141
|
+
* @param {any} value The value to test
|
|
142
|
+
* @returns {boolean} Return true if is number
|
|
143
|
+
*/
|
|
144
|
+
static isNum(value)
|
|
145
|
+
{
|
|
146
|
+
if ( typeof value === 'number' ) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if ( this.isStr(value) ) {
|
|
151
|
+
return /^-?[0-9]+(\.[0-9]+)?$/.test(value);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @see PicoMixed.isNum
|
|
159
|
+
*/
|
|
160
|
+
static isNumber = PicoMixed.isNum;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Check if the value is an integer
|
|
164
|
+
*
|
|
165
|
+
* @example Mix.isInt(12) // => true
|
|
166
|
+
* @example Mix.isInt('4') // => true
|
|
167
|
+
* @example Mix.isInt('-4.3') // => false
|
|
168
|
+
* @example Mix.isInt(3.4) // => false
|
|
169
|
+
*
|
|
170
|
+
* @param {any} value The value to test
|
|
171
|
+
* @returns {boolean} Return true if is integer
|
|
172
|
+
*/
|
|
173
|
+
static isInt(value)
|
|
174
|
+
{
|
|
175
|
+
if ( !this.isNum(value) ) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if ( this.isStr(value) ) {
|
|
180
|
+
return /^-?[0-9]+$/.test(value);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return parseInt(value) === parseFloat(value);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @see PicoMixed.isInt
|
|
188
|
+
*/
|
|
189
|
+
static isInteger = PicoMixed.isInt;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Check if the value is a boolean
|
|
193
|
+
*
|
|
194
|
+
* @example Mix.isBool(false) // => true
|
|
195
|
+
* @example Mix.isBool('true') // => true
|
|
196
|
+
* @example Mix.isBool(1) // => false
|
|
197
|
+
* @example Mix.isBool('1') // => false
|
|
198
|
+
*
|
|
199
|
+
* @param {any} value The value to test
|
|
200
|
+
* @returns {boolean} Return true if is boolean
|
|
201
|
+
*/
|
|
202
|
+
static isBool(value)
|
|
203
|
+
{
|
|
204
|
+
if ( typeof value === 'boolean' ) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if ( this.isStr(value) ) {
|
|
209
|
+
return /^(true|false)$/.test(value);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @see PicoMixed.isBool
|
|
217
|
+
*/
|
|
218
|
+
static isBoolean = PicoMixed.isBool;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Check if the value is a function
|
|
222
|
+
*
|
|
223
|
+
* @example Mix.isFunc(() => {}) // => true
|
|
224
|
+
* @example Mix.isFunc(Mix.isFunc) // => true
|
|
225
|
+
* @example Mix.isFunc({}) // => false
|
|
226
|
+
* @example Mix.isFunc('1') // => false
|
|
227
|
+
*
|
|
228
|
+
* @param {any} value The value to test
|
|
229
|
+
* @returns {boolean} Return true if is function
|
|
230
|
+
*/
|
|
231
|
+
static isFunc(value)
|
|
232
|
+
{
|
|
233
|
+
return typeof value === 'function';
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @see PicoMixed.isFunc
|
|
238
|
+
*/
|
|
239
|
+
static isFunction = PicoMixed.isFunc;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Check if the value is object
|
|
243
|
+
*
|
|
244
|
+
* @example Mix.isRef({}) // => true
|
|
245
|
+
* @example Mix.isRef([]) // => true
|
|
246
|
+
* @example Mix.isRef(() => {}) // => false
|
|
247
|
+
* @example Mix.isRef(null) // => false
|
|
248
|
+
* @example Mix.isRef(undefined) // => false
|
|
249
|
+
*
|
|
250
|
+
* @param {any} value The value to test
|
|
251
|
+
* @returns {boolean} Returns true if is an object
|
|
252
|
+
*/
|
|
253
|
+
static isRef(value)
|
|
254
|
+
{
|
|
255
|
+
if ( value == null ) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return typeof value === 'object';
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @see PicoMixed.isRef
|
|
264
|
+
*/
|
|
265
|
+
static isReference = PicoMixed.isRef;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Check if the value is plain object
|
|
269
|
+
*
|
|
270
|
+
* @example Mix.isObj({}) // => true
|
|
271
|
+
* @example Mix.isObj([]) // => false
|
|
272
|
+
*
|
|
273
|
+
* @param {any} value The value to test
|
|
274
|
+
* @returns {boolean} Returns true if is plain object
|
|
275
|
+
*/
|
|
276
|
+
static isObj(value)
|
|
277
|
+
{
|
|
278
|
+
if ( value == null ) {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return Object.getPrototypeOf(value) === Object.prototype;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* @see PicoMixed.isObj
|
|
287
|
+
*/
|
|
288
|
+
static isObject = PicoMixed.isObj;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Check if the value is array object
|
|
292
|
+
*
|
|
293
|
+
* @example Mix.isArr([]) // => true
|
|
294
|
+
* @example Mix.isArr({}) // => false
|
|
295
|
+
*
|
|
296
|
+
* @param {any} value The Value to test
|
|
297
|
+
* @returns {boolean} Returns true if is array object
|
|
298
|
+
*/
|
|
299
|
+
static isArr(value)
|
|
300
|
+
{
|
|
301
|
+
if ( value == null ) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return Object.getPrototypeOf(value) === Array.prototype;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* @see PicoMixed.isArr
|
|
310
|
+
*/
|
|
311
|
+
static isArray = PicoMixed.isArr;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Check if the value is iterable object
|
|
315
|
+
*
|
|
316
|
+
* @example Mix.isIter(new FormData()) // => true
|
|
317
|
+
* @example Mix.isIter({}) // => false
|
|
318
|
+
*
|
|
319
|
+
* @param {any} value The Value to test
|
|
320
|
+
* @returns {boolean} Returns true if is iterable object
|
|
321
|
+
*/
|
|
322
|
+
static isIter(value)
|
|
323
|
+
{
|
|
324
|
+
if ( this.isArr(value) ) {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if ( !this.isRef(value) ) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return this.isFunc(value.entries);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* @see PicoMixed.isIter
|
|
337
|
+
*/
|
|
338
|
+
static isIterable = PicoMixed.isIter;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Check if the value is iso date
|
|
342
|
+
*
|
|
343
|
+
* @example Mix.isIsoDate(new Date()) // => true
|
|
344
|
+
* @example Mix.isIsoDate(new Date()) // => true
|
|
345
|
+
* @example Mix.isIsoDate('2023-01-01 00:00:00') // => true
|
|
346
|
+
*
|
|
347
|
+
* @param {any} value The Value to test
|
|
348
|
+
* @returns {boolean} Returns true if is iso date
|
|
349
|
+
*/
|
|
350
|
+
static isIsoDate(value)
|
|
351
|
+
{
|
|
352
|
+
if ( value instanceof Date ) {
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return MIX_REGEX.iso.test(value);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Check if the value is valid date
|
|
361
|
+
*
|
|
362
|
+
* @example Mix.isIsoDate(new Date()) // => true
|
|
363
|
+
* @example Mix.isIsoDate('2023-01-01') // => true
|
|
364
|
+
* @example Mix.isIsoDate('2023-01-01 00:00:00') // => false
|
|
365
|
+
*
|
|
366
|
+
* @param {any} value The Value to test
|
|
367
|
+
* @returns {boolean} Returns true if is valid date
|
|
368
|
+
*/
|
|
369
|
+
static isDate(value)
|
|
370
|
+
{
|
|
371
|
+
if ( value instanceof Date ) {
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return /^\d{4}-\d{2}-\d{2}$/.test(value);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Check if the value is valid time
|
|
380
|
+
*
|
|
381
|
+
* @example Mix.isIsoDate(new Date()) // => true
|
|
382
|
+
* @example Mix.isIsoDate('00:00:00') // => true
|
|
383
|
+
* @example Mix.isIsoDate('2023-01-01 00:00:00') // => false
|
|
384
|
+
*
|
|
385
|
+
* @param {any} value The Value to test
|
|
386
|
+
* @returns {boolean} Returns true if is valid time
|
|
387
|
+
*/
|
|
388
|
+
static isTime(value)
|
|
389
|
+
{
|
|
390
|
+
if ( value instanceof Date ) {
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return /^\d{2}:\d{2}:\d{2}$/.test(value);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Check if value is equal
|
|
399
|
+
*
|
|
400
|
+
* @example Mix.isEqual(el, el) // => true
|
|
401
|
+
*
|
|
402
|
+
* @param {any} obj Source value
|
|
403
|
+
* @param {any} val Compare value
|
|
404
|
+
* @returns {boolean} True if equal
|
|
405
|
+
*/
|
|
406
|
+
static isEqual(obj, val)
|
|
407
|
+
{
|
|
408
|
+
if ( obj instanceof Node ) {
|
|
409
|
+
return obj.isEqualNode(val);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if ( this.isRef(obj) ) {
|
|
413
|
+
return Object.is(obj, val)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
return obj === val;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Convert iterable object to a regular object
|
|
421
|
+
*
|
|
422
|
+
* @example Mix.iter(new FormData()) // => {}
|
|
423
|
+
*
|
|
424
|
+
* @param {any} value Value to convert
|
|
425
|
+
* @returns {Record<string, any>} Converted object
|
|
426
|
+
*/
|
|
427
|
+
static iter(value)
|
|
428
|
+
{
|
|
429
|
+
if ( value == null ) {
|
|
430
|
+
return {};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
let result = {};
|
|
434
|
+
|
|
435
|
+
for ( const [key, val] of value.entries() ) {
|
|
436
|
+
result[key] = val;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return result;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Get keys of an object
|
|
444
|
+
*
|
|
445
|
+
* @example Mix.keys({a: 'v1', b: 'v2'}) // => ['a', 'b']
|
|
446
|
+
* @example Mix.keys(['v1', 'v2']) // => ['0', '1']
|
|
447
|
+
*
|
|
448
|
+
* @param {any} value Object to iterate
|
|
449
|
+
* @returns {Array<any>} Returns array with keys
|
|
450
|
+
*/
|
|
451
|
+
static keys(value)
|
|
452
|
+
{
|
|
453
|
+
if ( value == null ) {
|
|
454
|
+
return [];
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if ( this.isIter(value) ) {
|
|
458
|
+
value = this.iter(value);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return Object.keys(value);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Get values of an object
|
|
466
|
+
*
|
|
467
|
+
* @example Mix.vals({a: 'v1', b: 'v2'}) // => ['v1', 'v2']
|
|
468
|
+
* @example Mix.vals(['v1', 'v2']) // => ['v1', 'v2']
|
|
469
|
+
*
|
|
470
|
+
* @param {any} value Object to iterate
|
|
471
|
+
* @returns {Array<any>} Returns array with values
|
|
472
|
+
*/
|
|
473
|
+
static vals(value)
|
|
474
|
+
{
|
|
475
|
+
if ( value == null ) {
|
|
476
|
+
return [];
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if ( this.isIter(value) ) {
|
|
480
|
+
value = this.iter(value);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
if ( this.isArr(value) || !go().chrome ) {
|
|
484
|
+
return Object.values(value);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
let keys = this.keys(value);
|
|
488
|
+
|
|
489
|
+
for ( let i = 0; i < keys.length; i ++ ) {
|
|
490
|
+
keys[i] = value[keys[i]];
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return keys;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Cast to array
|
|
498
|
+
*
|
|
499
|
+
* @example Mix.nodes(nodeList) // => []
|
|
500
|
+
*
|
|
501
|
+
* @param {any} value Source value
|
|
502
|
+
* @returns {Array<any>} Array result
|
|
503
|
+
*/
|
|
504
|
+
static nodes(value)
|
|
505
|
+
{
|
|
506
|
+
return Array.prototype.slice.call(value);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Get own props excluding keys
|
|
511
|
+
*
|
|
512
|
+
* @example Mix.props(Math, ["PI"]) // => {}
|
|
513
|
+
*
|
|
514
|
+
* @param {any} value Source object
|
|
515
|
+
* @param {Array<any>} [exclude] Exclude keys
|
|
516
|
+
* @returns {Record<string, any>} Props map
|
|
517
|
+
*/
|
|
518
|
+
static props(value, exclude = [])
|
|
519
|
+
{
|
|
520
|
+
let result = {};
|
|
521
|
+
|
|
522
|
+
for ( const key of Object.getOwnPropertyNames(value) ) {
|
|
523
|
+
if ( exclude.length && ! Arr.has(exclude, key) ) {
|
|
524
|
+
result[key] = value[key];
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
return result;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Get static class props
|
|
533
|
+
*
|
|
534
|
+
* @example Mix.class(MyClass) // => {}
|
|
535
|
+
*
|
|
536
|
+
* @param {any} value Source class
|
|
537
|
+
* @param {Array<any>} [exclude] Exclude keys
|
|
538
|
+
* @returns {Record<string, any>} Props map
|
|
539
|
+
*/
|
|
540
|
+
static class(value, exclude = [])
|
|
541
|
+
{
|
|
542
|
+
exclude = Arr.merge(exclude, [
|
|
543
|
+
'length', 'name', 'prototype', 'constructor'
|
|
544
|
+
]);
|
|
545
|
+
|
|
546
|
+
return this.props(value, exclude);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Get prototype props
|
|
551
|
+
*
|
|
552
|
+
* @example Mix.proto(MyClass) // => {}
|
|
553
|
+
*
|
|
554
|
+
* @param {any} value Source class
|
|
555
|
+
* @param {Array<any>} [exclude] Exclude keys
|
|
556
|
+
* @returns {Record<string, any>} Props map
|
|
557
|
+
*/
|
|
558
|
+
static proto(value, exclude = [])
|
|
559
|
+
{
|
|
560
|
+
exclude = Arr.merge(exclude, [
|
|
561
|
+
'constructor'
|
|
562
|
+
]);
|
|
563
|
+
|
|
564
|
+
return this.props(value.prototype, exclude);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Create form data
|
|
569
|
+
*
|
|
570
|
+
* @example Mix.form({ a: 1 }) // => FormData
|
|
571
|
+
*
|
|
572
|
+
* @param {any} value Source object
|
|
573
|
+
* @returns {FormData} Form instance
|
|
574
|
+
*/
|
|
575
|
+
static form(value)
|
|
576
|
+
{
|
|
577
|
+
let form = new FormData();
|
|
578
|
+
|
|
579
|
+
Obj.each(Obj.flattenForm(value), (val, key) => {
|
|
580
|
+
form.append(key, val);
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
return form;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Loop over items
|
|
588
|
+
*
|
|
589
|
+
* @example Mix.vals(FormData, (val, key) => null) // => Mix
|
|
590
|
+
* @example Mix.vals(NodeList, (val, key) => null) // => Mix
|
|
591
|
+
*
|
|
592
|
+
* @param {any} value Value to loop
|
|
593
|
+
* @param {function} cb Callback for each loop
|
|
594
|
+
* @returns {PicoMixed} Returns Mix instance
|
|
595
|
+
*/
|
|
596
|
+
static each(value, cb)
|
|
597
|
+
{
|
|
598
|
+
if ( !this.isRef(value) ) {
|
|
599
|
+
throw new Error('Iterate non object');
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
for ( let key of Mix.keys(value) ) {
|
|
603
|
+
cb(value[key], key);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
return this;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Get length of value
|
|
611
|
+
*
|
|
612
|
+
* @example Mix.len({a: 'v1', b: 'v2'}) // => 2
|
|
613
|
+
* @example Mix.len(['v1', 'v2']) // => 2
|
|
614
|
+
* @example Mix.len('foobar') // => 6
|
|
615
|
+
* @example Mix.len(12) // => 2
|
|
616
|
+
*
|
|
617
|
+
* @param {any} value The value to count
|
|
618
|
+
* @returns {number} Returns length of value
|
|
619
|
+
*/
|
|
620
|
+
static len(value)
|
|
621
|
+
{
|
|
622
|
+
if ( this.isArr(value) ) {
|
|
623
|
+
return value.length;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
if ( ! this.isRef(value) ) {
|
|
627
|
+
return this.string(value).length;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
return this.keys(value).length;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* @see PicoMixed.length
|
|
635
|
+
*/
|
|
636
|
+
static length = PicoMixed.len;
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Compare two objects (used for natural array sort)
|
|
640
|
+
*
|
|
641
|
+
* @param {any} value First compare value
|
|
642
|
+
* @param {any} compare Second compare value
|
|
643
|
+
* @returns {number} Returns sort position
|
|
644
|
+
*/
|
|
645
|
+
static compare(value, compare)
|
|
646
|
+
{
|
|
647
|
+
return Locale.collator().compare(value, compare);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Get value as null
|
|
652
|
+
*
|
|
653
|
+
* @example Mix.null("null") // => null
|
|
654
|
+
*
|
|
655
|
+
* @param {any} value Input value
|
|
656
|
+
* @param {any} [fallback] Fallback value
|
|
657
|
+
* @returns {any} Null or fallback
|
|
658
|
+
*/
|
|
659
|
+
static null(value, fallback = null)
|
|
660
|
+
{
|
|
661
|
+
if ( value === 'null' ) {
|
|
662
|
+
return null;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
if ( this.isEmpty(value) ) {
|
|
666
|
+
return null;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
return fallback;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Cast to array
|
|
674
|
+
*
|
|
675
|
+
* @example Mix.arr("a,b") // => ["a", "b"]
|
|
676
|
+
*
|
|
677
|
+
* @param {any} value Source value
|
|
678
|
+
* @returns {Array<any>} Array result
|
|
679
|
+
*/
|
|
680
|
+
static arr(value)
|
|
681
|
+
{
|
|
682
|
+
if ( this.isArr(value) ) {
|
|
683
|
+
return value;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
if ( ! this.isStr(value) ) {
|
|
687
|
+
return [value];
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
value = value.replace(/^@?\[?(.*?)]$/g, '$1');
|
|
691
|
+
|
|
692
|
+
return Arr.each(value.split(','), (val) => {
|
|
693
|
+
return val.replace(/(^"|^'|'$|"$)/g, '');
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* @see PicoMixed.arr
|
|
699
|
+
*/
|
|
700
|
+
static array = PicoMixed.arr;
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Convert value to string
|
|
704
|
+
*
|
|
705
|
+
* @example Mix.str('foobar') // => 'foobar'
|
|
706
|
+
* @example Mix.str(12) // => '12'
|
|
707
|
+
* @example Mix.str(true) // => 'true'
|
|
708
|
+
* @example Mix.str(null) // => 'null'
|
|
709
|
+
* @example Mix.str(undefined) // => 'undefined'
|
|
710
|
+
*
|
|
711
|
+
* @param {any} value The value to convert
|
|
712
|
+
* @returns {string} Return value as string
|
|
713
|
+
*/
|
|
714
|
+
static str(value)
|
|
715
|
+
{
|
|
716
|
+
if ( this.isNix(value) ) {
|
|
717
|
+
return String(value);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
if ( value.toString === undefined ) {
|
|
721
|
+
return String(value);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
return value.toString();
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* @see PicoMixed.str
|
|
729
|
+
*/
|
|
730
|
+
static string = PicoMixed.str;
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Convert value to number
|
|
734
|
+
*
|
|
735
|
+
* @example Mix.num('-2.2') // => -2.2
|
|
736
|
+
* @example Mix.num(12) // => 12
|
|
737
|
+
* @example Mix.num('foobar') // => NaN
|
|
738
|
+
* @example Mix.num(true) // => NaN
|
|
739
|
+
*
|
|
740
|
+
* @param {any} value The value to convert
|
|
741
|
+
* @param {any} fallback Fallback incase it is not primitive
|
|
742
|
+
* @returns {number|any} Return value as number
|
|
743
|
+
*/
|
|
744
|
+
static num(value, fallback = NaN)
|
|
745
|
+
{
|
|
746
|
+
if ( !this.isPrim(value) ) {
|
|
747
|
+
return fallback;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
if ( this.isStr(value) ) {
|
|
751
|
+
value = parseFloat(value);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
return value;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* @see PicoMixed.num
|
|
759
|
+
*/
|
|
760
|
+
static number = PicoMixed.num;
|
|
761
|
+
|
|
762
|
+
/**
|
|
763
|
+
* Convert value to integer
|
|
764
|
+
*
|
|
765
|
+
* @example Mix.int('-2.2') // => -2
|
|
766
|
+
* @example Mix.int(12) // => 12
|
|
767
|
+
* @example Mix.int('foobar') // => NaN
|
|
768
|
+
* @example Mix.int(true) // => NaN
|
|
769
|
+
*
|
|
770
|
+
* @param {any} value The value to convert
|
|
771
|
+
* @param {any} fallback Fallback incase it is not primitive
|
|
772
|
+
* @returns {number|any} Return value as integer
|
|
773
|
+
*/
|
|
774
|
+
static int(value, fallback = NaN)
|
|
775
|
+
{
|
|
776
|
+
if ( !this.isPrim(value) ) {
|
|
777
|
+
return fallback;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
if ( this.isStr(value) ) {
|
|
781
|
+
value = parseFloat(value);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
return Math.round(value);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* @see PicoMixed.int
|
|
789
|
+
*/
|
|
790
|
+
static integer = PicoMixed.int;
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* Convert value to boolean
|
|
794
|
+
*
|
|
795
|
+
* @example Mix.int(true) // => true
|
|
796
|
+
* @example Mix.int(12) // => true
|
|
797
|
+
* @example Mix.int(0) // => false
|
|
798
|
+
* @example Mix.int('yes') // => true
|
|
799
|
+
* @example Mix.int('foobar') // => false
|
|
800
|
+
* @example Mix.int(['v1']) // => true
|
|
801
|
+
* @example Mix.int({}) // => false
|
|
802
|
+
*
|
|
803
|
+
* @param {any} value The value to convert
|
|
804
|
+
* @returns {boolean} Return value as boolean
|
|
805
|
+
*/
|
|
806
|
+
static bool(value)
|
|
807
|
+
{
|
|
808
|
+
if ( this.isRef(value) ) {
|
|
809
|
+
return !!this.vals(value).length;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
if ( this.isNum(value) ) {
|
|
813
|
+
return this.num(value) !== 0;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
return /^(true|yes)$/i.test(value);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* @see PicoMixed.bool
|
|
821
|
+
*/
|
|
822
|
+
static boolean = PicoMixed.bool;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
PicoMixed.global = function (...args) {
|
|
826
|
+
console.warn('Mix.global() is deprecated, use go() instead.');
|
|
827
|
+
return go(...args);
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
PicoMixed.isPlain = function (...args) {
|
|
831
|
+
console.warn('Mix.isPlain() is deprecated, use Mix.isObj() instead.');
|
|
832
|
+
return Mix.isObj(...args);
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
PicoMixed.float = function (...args) {
|
|
836
|
+
console.warn('Mix.float() is deprecated, use Mix.num() instead.');
|
|
837
|
+
return Mix.num(...args);
|
|
838
|
+
};
|
|
839
|
+
|
|
840
|
+
PicoMixed.delay = function (...args) {
|
|
841
|
+
console.warn('Mix.delay() is deprecated, use Run.delay() instead.');
|
|
842
|
+
return Run.delay(...args);
|
|
843
|
+
};
|
|
844
|
+
|
|
845
|
+
PicoMixed.async = function (...args) {
|
|
846
|
+
console.warn('Mix.async() is deprecated, use Run.async() instead.');
|
|
847
|
+
return Run.async(...args);
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
PicoMixed.debounce = function (...args) {
|
|
851
|
+
console.warn('Mix.debounce() is deprecated, use Run.debounce() instead.');
|
|
852
|
+
return Run.debounce(...args);
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
PicoMixed.throttle = function (...args) {
|
|
856
|
+
console.warn('Mix.throttle() is deprecated, use Run.throttle() instead.');
|
|
857
|
+
return Run.throttle(...args);
|
|
858
|
+
};
|
|
859
|
+
|
|
860
|
+
PicoMixed.framerate = function (...args) {
|
|
861
|
+
console.warn('Mix.framerate() is deprecated, use Run.framerate() instead.');
|
|
862
|
+
return Run.framerate(...args);
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
PicoMixed.convertString = function (...args) {
|
|
866
|
+
console.warn('Mix.convertString() is deprecated, use Str.string() instead.');
|
|
867
|
+
return Str.string(...args);
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
PicoMixed.convertDatetime = function (...args) {
|
|
871
|
+
console.warn('Mix.convertDatetime() is deprecated, use Str.date() instead.');
|
|
872
|
+
return Str.date(...args);
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
PicoMixed.convertBool = function (...args) {
|
|
876
|
+
console.warn('Mix.convertBool() is deprecated, use Str.boolean() instead.');
|
|
877
|
+
return Str.boolean(...args);
|
|
878
|
+
};
|
|
879
|
+
|
|
880
|
+
PicoMixed.convertBoolean = function (...args) {
|
|
881
|
+
console.warn('Mix.convertBoolean() is deprecated, use Str.boolean() instead.');
|
|
882
|
+
return Str.boolean(...args);
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
export default PicoMixed;
|