@kizmann/pico-js 2.0.7 → 2.0.9
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.browser.js +1 -1
- package/dist/pico-js.browser.js.map +1 -1
- package/dist/pico-js.esm.js +1 -1
- package/dist/pico-js.esm.js.map +1 -1
- package/package.json +4 -6
- package/src/dom/{DomAttribute.js → DomAttribute.ts} +40 -63
- package/src/dom/{DomBuilder.js → DomBuilder.ts} +27 -44
- package/src/dom/{DomEvent.js → DomEvent.ts} +101 -76
- package/src/dom/{DomFinder.js → DomFinder.ts} +103 -139
- package/src/dom/DomForm.ts +38 -0
- package/src/dom/{DomGlobal.js → DomGlobal.ts} +34 -51
- package/src/dom/{DomInview.js → DomInview.ts} +37 -57
- package/src/dom/DomMeta.ts +48 -0
- package/src/dom/DomObserver.ts +17 -0
- package/src/dom/{DomPopover.js → DomPopover.ts} +20 -39
- package/src/dom/{DomRectangle.js → DomRectangle.ts} +70 -87
- package/src/format/{FormatFile.js → FormatFile.ts} +12 -23
- package/src/format/{FormatOption.js → FormatOption.ts} +15 -24
- package/src/format/{FormatParam.js → FormatParam.ts} +14 -25
- package/src/format/{FormatParser.js → FormatParser.ts} +29 -39
- package/src/format/{FormatUrl.js → FormatUrl.ts} +9 -21
- package/src/index.browser.ts +32 -0
- package/src/index.esm.ts +64 -0
- package/src/now/{NowDefault.js → NowDefault.ts} +86 -121
- package/src/now/{NowFormat.js → NowFormat.ts} +23 -28
- package/src/now/{NowGrid.js → NowGrid.ts} +41 -58
- package/src/now/{NowHuman.js → NowHuman.ts} +18 -27
- package/src/now/{NowMatch.js → NowMatch.ts} +22 -28
- package/src/now/{NowRange.js → NowRange.ts} +13 -22
- package/src/now/{NowWalker.js → NowWalker.ts} +65 -71
- package/src/tool/{scope.js → scope.ts} +41 -11
- package/src/utils/{Array.js → Array.ts} +187 -152
- package/src/utils/{Cookie.js → Cookie.ts} +15 -12
- package/src/utils/{Data.js → Data.ts} +17 -17
- package/src/utils/Dom.ts +204 -0
- package/src/utils/Format.ts +48 -0
- package/src/utils/{Hash.js → Hash.ts} +20 -20
- package/src/utils/{Locale.js → Locale.ts} +21 -21
- package/src/utils/{Mixed.js → Mixed.ts} +104 -61
- package/src/utils/{Now.js → Now.ts} +68 -69
- package/src/utils/{Number.js → Number.ts} +34 -36
- package/src/utils/{Object.js → Object.ts} +68 -122
- package/src/utils/{Route.js → Route.ts} +11 -9
- package/src/utils/{Runner.js → Runner.ts} +89 -77
- package/src/utils/{Signal.js → Signal.ts} +35 -22
- package/src/utils/{String.js → String.ts} +79 -69
- package/src/wip/{Element.js → Element.ts} +2 -2
- package/src/wip/{Map.js → Map.ts} +1 -1
- package/types/dom/DomAttribute.d.ts +16 -27
- package/types/dom/DomBuilder.d.ts +6 -9
- package/types/dom/DomEvent.d.ts +19 -24
- package/types/dom/DomFinder.d.ts +38 -61
- package/types/dom/DomForm.d.ts +7 -10
- package/types/dom/DomGlobal.d.ts +8 -15
- package/types/dom/DomInview.d.ts +9 -19
- package/types/dom/DomMeta.d.ts +9 -16
- package/types/dom/DomObserver.d.ts +4 -8
- package/types/dom/DomPopover.d.ts +8 -11
- package/types/dom/DomRectangle.d.ts +21 -35
- package/types/format/FormatFile.d.ts +5 -8
- package/types/format/FormatOption.d.ts +6 -8
- package/types/format/FormatParam.d.ts +6 -9
- package/types/format/FormatParser.d.ts +10 -18
- package/types/format/FormatUrl.d.ts +5 -8
- package/types/index.esm.d.ts +25 -37
- package/types/now/NowDefault.d.ts +30 -99
- package/types/now/NowFormat.d.ts +8 -21
- package/types/now/NowGrid.d.ts +24 -46
- package/types/now/NowHuman.d.ts +10 -11
- package/types/now/NowMatch.d.ts +6 -4
- package/types/now/NowRange.d.ts +5 -8
- package/types/now/NowWalker.d.ts +6 -4
- package/types/tool/scope.d.ts +11 -3
- package/types/utils/Array.d.ts +83 -101
- package/types/utils/Cookie.d.ts +11 -8
- package/types/utils/Data.d.ts +7 -7
- package/types/utils/Dom.d.ts +63 -96
- package/types/utils/Format.d.ts +15 -28
- package/types/utils/Hash.d.ts +21 -21
- package/types/utils/Locale.d.ts +9 -9
- package/types/utils/Mixed.d.ts +19 -32
- package/types/utils/Now.d.ts +51 -56
- package/types/utils/Number.d.ts +9 -20
- package/types/utils/Object.d.ts +21 -36
- package/types/utils/Route.d.ts +5 -2
- package/types/utils/Runner.d.ts +45 -38
- package/types/utils/Signal.d.ts +16 -16
- package/types/utils/String.d.ts +40 -76
- package/src/dom/DomForm.js +0 -59
- package/src/dom/DomMeta.js +0 -68
- package/src/dom/DomObserver.js +0 -38
- package/src/index.browser.js +0 -36
- package/src/index.esm.js +0 -80
- package/src/utils/Dom.js +0 -214
- package/src/utils/Format.js +0 -62
- package/types/wip/Element.d.ts +0 -119
- package/types/wip/Map.d.ts +0 -254
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { Mix, Obj, Locale } from "../index.esm.
|
|
1
|
+
import { Mix, Obj, Locale } from "../index.esm.ts";
|
|
2
2
|
|
|
3
3
|
export class PicoLocale
|
|
4
4
|
{
|
|
5
5
|
/**
|
|
6
6
|
* Translation dictionary
|
|
7
7
|
*
|
|
8
|
-
* @type {
|
|
8
|
+
* @type {any}
|
|
9
9
|
*/
|
|
10
|
-
static $text = {};
|
|
10
|
+
static $text : any = {};
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Cached collator instance
|
|
14
14
|
*
|
|
15
15
|
* @type {Intl.Collator|null}
|
|
16
16
|
*/
|
|
17
|
-
static $sort
|
|
17
|
+
static $sort : Intl.Collator;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Active locale code
|
|
21
21
|
*
|
|
22
22
|
* @type {string}
|
|
23
23
|
*/
|
|
24
|
-
static $code = 'en';
|
|
24
|
+
static $code : string = 'en';
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Check if translation key exists
|
|
@@ -32,13 +32,13 @@ export class PicoLocale
|
|
|
32
32
|
* @param {any} [key] Translation key
|
|
33
33
|
* @returns {boolean} True if exists
|
|
34
34
|
*/
|
|
35
|
-
static has(key = undefined)
|
|
35
|
+
static has(key : any = undefined) : boolean
|
|
36
36
|
{
|
|
37
37
|
if ( key === undefined ) {
|
|
38
38
|
return true;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
return
|
|
41
|
+
return Obj.has(PicoLocale.$text, key);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
@@ -51,7 +51,7 @@ export class PicoLocale
|
|
|
51
51
|
* @param {any} [fallback] Fallback value
|
|
52
52
|
* @returns {any} Translation value
|
|
53
53
|
*/
|
|
54
|
-
static get(key = undefined, fallback = null)
|
|
54
|
+
static get(key : any = undefined, fallback : any = null) : any
|
|
55
55
|
{
|
|
56
56
|
if ( key === undefined ) {
|
|
57
57
|
return PicoLocale.$text;
|
|
@@ -70,7 +70,7 @@ export class PicoLocale
|
|
|
70
70
|
* @param {any} [value] Value to set
|
|
71
71
|
* @returns {any} Updated map
|
|
72
72
|
*/
|
|
73
|
-
static set(key = undefined, value = undefined)
|
|
73
|
+
static set(key : any = undefined, value : any = undefined) : any
|
|
74
74
|
{
|
|
75
75
|
if ( value === undefined ) {
|
|
76
76
|
return PicoLocale.$text = key;
|
|
@@ -85,16 +85,16 @@ export class PicoLocale
|
|
|
85
85
|
* @example Locale.code() // => "en"
|
|
86
86
|
* @example Locale.code("de") // => "de"
|
|
87
87
|
*
|
|
88
|
-
* @param {string
|
|
88
|
+
* @param {string} [code] Locale code
|
|
89
89
|
* @returns {string} Active code
|
|
90
90
|
*/
|
|
91
|
-
static code(code = null)
|
|
91
|
+
static code(code : string = null) : string
|
|
92
92
|
{
|
|
93
|
-
if ( !
|
|
93
|
+
if ( !Mix.isNull(code) ) {
|
|
94
94
|
return Locale.$code = code;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
if ( !
|
|
97
|
+
if ( !Mix.isNull(Locale.$code) ) {
|
|
98
98
|
return Locale.$code;
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -111,9 +111,9 @@ export class PicoLocale
|
|
|
111
111
|
*
|
|
112
112
|
* @returns {Intl.Collator} Collator instance
|
|
113
113
|
*/
|
|
114
|
-
static collator()
|
|
114
|
+
static collator() : Intl.Collator
|
|
115
115
|
{
|
|
116
|
-
if ( !
|
|
116
|
+
if ( !Mix.isNull(Locale.$sort) ) {
|
|
117
117
|
return Locale.$sort;
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -134,13 +134,13 @@ export class PicoLocale
|
|
|
134
134
|
* @param {any} [replace] Replace map
|
|
135
135
|
* @returns {string} Replaced text
|
|
136
136
|
*/
|
|
137
|
-
static replace(text, replace = null)
|
|
137
|
+
static replace(text : string, replace : any = null) : string
|
|
138
138
|
{
|
|
139
139
|
if ( replace == null ) {
|
|
140
140
|
return text;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
Obj.each(replace, (val, key) => {
|
|
143
|
+
Obj.each(replace, (val : any, key : any) => {
|
|
144
144
|
text = text.replace(new RegExp(':' + key, 'g'), val);
|
|
145
145
|
});
|
|
146
146
|
|
|
@@ -157,7 +157,7 @@ export class PicoLocale
|
|
|
157
157
|
* @param {any} [replace] Replace map
|
|
158
158
|
* @returns {string} Translated text
|
|
159
159
|
*/
|
|
160
|
-
static trans(text, replace = null)
|
|
160
|
+
static trans(text : string, replace : any = null) : string
|
|
161
161
|
{
|
|
162
162
|
text = Obj.get(PicoLocale.$text, text, text);
|
|
163
163
|
|
|
@@ -175,7 +175,7 @@ export class PicoLocale
|
|
|
175
175
|
* @param {any} [replace] Replace map
|
|
176
176
|
* @returns {string} Chosen text
|
|
177
177
|
*/
|
|
178
|
-
static choice(text, count = 0, replace = {})
|
|
178
|
+
static choice(text : string, count : number = 0, replace : any = {}) : string
|
|
179
179
|
{
|
|
180
180
|
text = Obj.get(PicoLocale.$text, text, text);
|
|
181
181
|
|
|
@@ -193,11 +193,11 @@ export class PicoLocale
|
|
|
193
193
|
*
|
|
194
194
|
* @example Locale.countpick(["a","b"], 2) // => "b"
|
|
195
195
|
*
|
|
196
|
-
* @param {
|
|
196
|
+
* @param {string[]} splits Variant list
|
|
197
197
|
* @param {number} count Choice count
|
|
198
198
|
* @returns {string} Picked text
|
|
199
199
|
*/
|
|
200
|
-
static countpick(splits, count)
|
|
200
|
+
static countpick(splits : string[], count : number = 0) : string
|
|
201
201
|
{
|
|
202
202
|
let length = splits.length;
|
|
203
203
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { go, Arr, Mix, Run,
|
|
1
|
+
import { go, Arr, Mix, Run, Locale, Str, Obj } from "../index.esm.ts";
|
|
2
2
|
|
|
3
3
|
export const MIX_REGEX = {
|
|
4
4
|
'iso': /^\d{4}-\d{2}-\d{2}[T\s]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/,
|
|
@@ -18,7 +18,7 @@ export class PicoMixed
|
|
|
18
18
|
* @param {any} value The value to test
|
|
19
19
|
* @returns {boolean} Returns true if value is not empty
|
|
20
20
|
*/
|
|
21
|
-
static isEmpty(value)
|
|
21
|
+
static isEmpty(value : any) : boolean
|
|
22
22
|
{
|
|
23
23
|
if ( value == null ) {
|
|
24
24
|
return true;
|
|
@@ -54,7 +54,7 @@ export class PicoMixed
|
|
|
54
54
|
* @param {any} value The value to test
|
|
55
55
|
* @returns {boolean} Return true if null
|
|
56
56
|
*/
|
|
57
|
-
static isNull(value)
|
|
57
|
+
static isNull(value : any) : boolean
|
|
58
58
|
{
|
|
59
59
|
return value === null;
|
|
60
60
|
}
|
|
@@ -70,7 +70,7 @@ export class PicoMixed
|
|
|
70
70
|
* @param {any} value The value to test
|
|
71
71
|
* @returns {boolean} Return true if undefined
|
|
72
72
|
*/
|
|
73
|
-
static isUndef(value)
|
|
73
|
+
static isUndef(value : any) : boolean
|
|
74
74
|
{
|
|
75
75
|
return value === undefined;
|
|
76
76
|
}
|
|
@@ -86,7 +86,7 @@ export class PicoMixed
|
|
|
86
86
|
* @param {any} value The value to test
|
|
87
87
|
* @returns {boolean} Return true if null or undefined
|
|
88
88
|
*/
|
|
89
|
-
static isNix(value)
|
|
89
|
+
static isNix(value : any) : boolean
|
|
90
90
|
{
|
|
91
91
|
return value === undefined || value === null;
|
|
92
92
|
}
|
|
@@ -102,7 +102,7 @@ export class PicoMixed
|
|
|
102
102
|
* @param {any} value The value to test
|
|
103
103
|
* @returns {boolean} Return true if typeof string or number
|
|
104
104
|
*/
|
|
105
|
-
static isPrim(value)
|
|
105
|
+
static isPrim(value : any) : boolean
|
|
106
106
|
{
|
|
107
107
|
return typeof value === 'string' || typeof value === 'number';
|
|
108
108
|
}
|
|
@@ -121,7 +121,7 @@ export class PicoMixed
|
|
|
121
121
|
* @param {any} value The value to test
|
|
122
122
|
* @returns {boolean} Return true if is string
|
|
123
123
|
*/
|
|
124
|
-
static isStr(value)
|
|
124
|
+
static isStr(value : any) : boolean
|
|
125
125
|
{
|
|
126
126
|
return typeof value === 'string';
|
|
127
127
|
}
|
|
@@ -141,7 +141,7 @@ export class PicoMixed
|
|
|
141
141
|
* @param {any} value The value to test
|
|
142
142
|
* @returns {boolean} Return true if is number
|
|
143
143
|
*/
|
|
144
|
-
static isNum(value)
|
|
144
|
+
static isNum(value : any) : boolean
|
|
145
145
|
{
|
|
146
146
|
if ( typeof value === 'number' ) {
|
|
147
147
|
return true;
|
|
@@ -170,7 +170,7 @@ export class PicoMixed
|
|
|
170
170
|
* @param {any} value The value to test
|
|
171
171
|
* @returns {boolean} Return true if is integer
|
|
172
172
|
*/
|
|
173
|
-
static isInt(value)
|
|
173
|
+
static isInt(value : any) : boolean
|
|
174
174
|
{
|
|
175
175
|
if ( !this.isNum(value) ) {
|
|
176
176
|
return false;
|
|
@@ -199,7 +199,7 @@ export class PicoMixed
|
|
|
199
199
|
* @param {any} value The value to test
|
|
200
200
|
* @returns {boolean} Return true if is boolean
|
|
201
201
|
*/
|
|
202
|
-
static isBool(value)
|
|
202
|
+
static isBool(value : any) : boolean
|
|
203
203
|
{
|
|
204
204
|
if ( typeof value === 'boolean' ) {
|
|
205
205
|
return true;
|
|
@@ -228,7 +228,7 @@ export class PicoMixed
|
|
|
228
228
|
* @param {any} value The value to test
|
|
229
229
|
* @returns {boolean} Return true if is function
|
|
230
230
|
*/
|
|
231
|
-
static isFunc(value)
|
|
231
|
+
static isFunc(value : any) : boolean
|
|
232
232
|
{
|
|
233
233
|
return typeof value === 'function';
|
|
234
234
|
}
|
|
@@ -250,7 +250,7 @@ export class PicoMixed
|
|
|
250
250
|
* @param {any} value The value to test
|
|
251
251
|
* @returns {boolean} Returns true if is an object
|
|
252
252
|
*/
|
|
253
|
-
static isRef(value)
|
|
253
|
+
static isRef(value : any) : boolean
|
|
254
254
|
{
|
|
255
255
|
if ( value == null ) {
|
|
256
256
|
return false;
|
|
@@ -273,7 +273,7 @@ export class PicoMixed
|
|
|
273
273
|
* @param {any} value The value to test
|
|
274
274
|
* @returns {boolean} Returns true if is plain object
|
|
275
275
|
*/
|
|
276
|
-
static isObj(value)
|
|
276
|
+
static isObj(value : any) : boolean
|
|
277
277
|
{
|
|
278
278
|
if ( value == null ) {
|
|
279
279
|
return false;
|
|
@@ -296,7 +296,7 @@ export class PicoMixed
|
|
|
296
296
|
* @param {any} value The Value to test
|
|
297
297
|
* @returns {boolean} Returns true if is array object
|
|
298
298
|
*/
|
|
299
|
-
static isArr(value)
|
|
299
|
+
static isArr(value : any) : boolean
|
|
300
300
|
{
|
|
301
301
|
if ( value == null ) {
|
|
302
302
|
return false;
|
|
@@ -319,7 +319,7 @@ export class PicoMixed
|
|
|
319
319
|
* @param {any} value The Value to test
|
|
320
320
|
* @returns {boolean} Returns true if is iterable object
|
|
321
321
|
*/
|
|
322
|
-
static isIter(value)
|
|
322
|
+
static isIter(value : any) : boolean
|
|
323
323
|
{
|
|
324
324
|
if ( this.isArr(value) ) {
|
|
325
325
|
return false;
|
|
@@ -347,7 +347,7 @@ export class PicoMixed
|
|
|
347
347
|
* @param {any} value The Value to test
|
|
348
348
|
* @returns {boolean} Returns true if is iso date
|
|
349
349
|
*/
|
|
350
|
-
static isIsoDate(value)
|
|
350
|
+
static isIsoDate(value : any) : boolean
|
|
351
351
|
{
|
|
352
352
|
if ( value instanceof Date ) {
|
|
353
353
|
return true;
|
|
@@ -366,7 +366,7 @@ export class PicoMixed
|
|
|
366
366
|
* @param {any} value The Value to test
|
|
367
367
|
* @returns {boolean} Returns true if is valid date
|
|
368
368
|
*/
|
|
369
|
-
static isDate(value)
|
|
369
|
+
static isDate(value : any) : boolean
|
|
370
370
|
{
|
|
371
371
|
if ( value instanceof Date ) {
|
|
372
372
|
return true;
|
|
@@ -385,7 +385,7 @@ export class PicoMixed
|
|
|
385
385
|
* @param {any} value The Value to test
|
|
386
386
|
* @returns {boolean} Returns true if is valid time
|
|
387
387
|
*/
|
|
388
|
-
static isTime(value)
|
|
388
|
+
static isTime(value : any) : boolean
|
|
389
389
|
{
|
|
390
390
|
if ( value instanceof Date ) {
|
|
391
391
|
return true;
|
|
@@ -403,7 +403,7 @@ export class PicoMixed
|
|
|
403
403
|
* @param {any} val Compare value
|
|
404
404
|
* @returns {boolean} True if equal
|
|
405
405
|
*/
|
|
406
|
-
static isEqual(obj, val)
|
|
406
|
+
static isEqual(obj : any, val : any) : boolean
|
|
407
407
|
{
|
|
408
408
|
if ( obj instanceof Node ) {
|
|
409
409
|
return obj.isEqualNode(val);
|
|
@@ -424,7 +424,7 @@ export class PicoMixed
|
|
|
424
424
|
* @param {any} value Value to convert
|
|
425
425
|
* @returns {Record<string, any>} Converted object
|
|
426
426
|
*/
|
|
427
|
-
static iter(value)
|
|
427
|
+
static iter(value : any) : Record<string, any>
|
|
428
428
|
{
|
|
429
429
|
if ( value == null ) {
|
|
430
430
|
return {};
|
|
@@ -448,7 +448,7 @@ export class PicoMixed
|
|
|
448
448
|
* @param {any} value Object to iterate
|
|
449
449
|
* @returns {Array<any>} Returns array with keys
|
|
450
450
|
*/
|
|
451
|
-
static keys(value)
|
|
451
|
+
static keys(value : any) : Array<any>
|
|
452
452
|
{
|
|
453
453
|
if ( value == null ) {
|
|
454
454
|
return [];
|
|
@@ -474,7 +474,7 @@ export class PicoMixed
|
|
|
474
474
|
* @param {any} value Object to iterate
|
|
475
475
|
* @returns {Array<any>} Returns array with values
|
|
476
476
|
*/
|
|
477
|
-
static vals(value)
|
|
477
|
+
static vals(value : any) : Array<any>
|
|
478
478
|
{
|
|
479
479
|
if ( value == null ) {
|
|
480
480
|
return [];
|
|
@@ -494,7 +494,7 @@ export class PicoMixed
|
|
|
494
494
|
|
|
495
495
|
let keys = this.keys(value);
|
|
496
496
|
|
|
497
|
-
for ( let i = 0; i < keys.length; i
|
|
497
|
+
for ( let i = 0; i < keys.length; i++ ) {
|
|
498
498
|
keys[i] = value[keys[i]];
|
|
499
499
|
}
|
|
500
500
|
|
|
@@ -509,7 +509,7 @@ export class PicoMixed
|
|
|
509
509
|
* @param {any} value Source value
|
|
510
510
|
* @returns {Array<any>} Array result
|
|
511
511
|
*/
|
|
512
|
-
static nodes(value)
|
|
512
|
+
static nodes(value : any) : Array<any>
|
|
513
513
|
{
|
|
514
514
|
return Array.prototype.slice.call(value);
|
|
515
515
|
}
|
|
@@ -520,15 +520,15 @@ export class PicoMixed
|
|
|
520
520
|
* @example Mix.props(Math, ["PI"]) // => {}
|
|
521
521
|
*
|
|
522
522
|
* @param {any} value Source object
|
|
523
|
-
* @param {
|
|
523
|
+
* @param {string[]} [exclude] Exclude keys
|
|
524
524
|
* @returns {Record<string, any>} Props map
|
|
525
525
|
*/
|
|
526
|
-
static props(value, exclude = [])
|
|
526
|
+
static props(value : any, exclude : string[] = []) : Record<string, any>
|
|
527
527
|
{
|
|
528
528
|
let result = {};
|
|
529
529
|
|
|
530
530
|
for ( const key of Object.getOwnPropertyNames(value) ) {
|
|
531
|
-
if ( exclude.length && !
|
|
531
|
+
if ( exclude.length && !Arr.has(exclude, key) ) {
|
|
532
532
|
result[key] = value[key];
|
|
533
533
|
}
|
|
534
534
|
}
|
|
@@ -536,16 +536,48 @@ export class PicoMixed
|
|
|
536
536
|
return result;
|
|
537
537
|
}
|
|
538
538
|
|
|
539
|
+
static extend(target : any, value : any, exclude : string[] = ['constructor'])
|
|
540
|
+
{
|
|
541
|
+
if ( value == null ) {
|
|
542
|
+
return {};
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
let proto = Object.getPrototypeOf(value);
|
|
546
|
+
|
|
547
|
+
for ( const key of Object.getOwnPropertyNames(value) ) {
|
|
548
|
+
|
|
549
|
+
if ( !exclude.length || Arr.has(exclude, key) ) {
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
let desc = Object.getOwnPropertyDescriptor(proto, key);
|
|
554
|
+
|
|
555
|
+
if ( !desc ) {
|
|
556
|
+
desc = Object.getOwnPropertyDescriptor(value, key);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
if ( !desc && (!desc.get && !desc.set) ) {
|
|
560
|
+
target[key] = value[key];
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
if ( desc && (desc.get || desc.set) ) {
|
|
564
|
+
Object.defineProperty(target, key, desc);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
return target;
|
|
569
|
+
}
|
|
570
|
+
|
|
539
571
|
/**
|
|
540
572
|
* Get static class props
|
|
541
573
|
*
|
|
542
574
|
* @example Mix.class(MyClass) // => {}
|
|
543
575
|
*
|
|
544
576
|
* @param {any} value Source class
|
|
545
|
-
* @param {
|
|
577
|
+
* @param {string[any]} [exclude] Exclude keys
|
|
546
578
|
* @returns {Record<string, any>} Props map
|
|
547
579
|
*/
|
|
548
|
-
static class(value, exclude = [])
|
|
580
|
+
static class(value : any, exclude : string[] = []) : Record<string, any>
|
|
549
581
|
{
|
|
550
582
|
exclude = Arr.merge(exclude, [
|
|
551
583
|
'length', 'name', 'prototype', 'constructor'
|
|
@@ -560,10 +592,10 @@ export class PicoMixed
|
|
|
560
592
|
* @example Mix.proto(MyClass) // => {}
|
|
561
593
|
*
|
|
562
594
|
* @param {any} value Source class
|
|
563
|
-
* @param {
|
|
595
|
+
* @param {string[]} [exclude] Exclude keys
|
|
564
596
|
* @returns {Record<string, any>} Props map
|
|
565
597
|
*/
|
|
566
|
-
static proto(value, exclude = [])
|
|
598
|
+
static proto(value : any, exclude : string[] = []) : Record<string, any>
|
|
567
599
|
{
|
|
568
600
|
exclude = Arr.merge(exclude, [
|
|
569
601
|
'constructor'
|
|
@@ -580,11 +612,11 @@ export class PicoMixed
|
|
|
580
612
|
* @param {any} value Source object
|
|
581
613
|
* @returns {FormData} Form instance
|
|
582
614
|
*/
|
|
583
|
-
static form(value)
|
|
615
|
+
static form(value : any) : FormData
|
|
584
616
|
{
|
|
585
617
|
let form = new FormData();
|
|
586
618
|
|
|
587
|
-
Obj.each(Obj.flattenForm(value), (val, key) => {
|
|
619
|
+
Obj.each(Obj.flattenForm(value), (val : any, key : any) => {
|
|
588
620
|
form.append(key, val);
|
|
589
621
|
});
|
|
590
622
|
|
|
@@ -598,10 +630,10 @@ export class PicoMixed
|
|
|
598
630
|
* @example Mix.vals(NodeList, (val, key) => null) // => Mix
|
|
599
631
|
*
|
|
600
632
|
* @param {any} value Value to loop
|
|
601
|
-
* @param {
|
|
633
|
+
* @param {Function} cb Callback for each loop
|
|
602
634
|
* @returns {PicoMixed} Returns Mix instance
|
|
603
635
|
*/
|
|
604
|
-
static each(value, cb)
|
|
636
|
+
static each(value : any, cb : Function) : PicoMixed
|
|
605
637
|
{
|
|
606
638
|
if ( !this.isRef(value) ) {
|
|
607
639
|
throw new Error('Iterate non object');
|
|
@@ -625,13 +657,13 @@ export class PicoMixed
|
|
|
625
657
|
* @param {any} value The value to count
|
|
626
658
|
* @returns {number} Returns length of value
|
|
627
659
|
*/
|
|
628
|
-
static len(value)
|
|
660
|
+
static len(value : any) : number
|
|
629
661
|
{
|
|
630
662
|
if ( this.isArr(value) ) {
|
|
631
663
|
return value.length;
|
|
632
664
|
}
|
|
633
665
|
|
|
634
|
-
if ( !
|
|
666
|
+
if ( !this.isRef(value) ) {
|
|
635
667
|
return this.string(value).length;
|
|
636
668
|
}
|
|
637
669
|
|
|
@@ -650,7 +682,7 @@ export class PicoMixed
|
|
|
650
682
|
* @param {any} compare Second compare value
|
|
651
683
|
* @returns {number} Returns sort position
|
|
652
684
|
*/
|
|
653
|
-
static compare(value, compare)
|
|
685
|
+
static compare(value : any, compare : any) : number
|
|
654
686
|
{
|
|
655
687
|
return Locale.collator().compare(value, compare);
|
|
656
688
|
}
|
|
@@ -664,7 +696,7 @@ export class PicoMixed
|
|
|
664
696
|
* @param {any} [fallback] Fallback value
|
|
665
697
|
* @returns {any} Null or fallback
|
|
666
698
|
*/
|
|
667
|
-
static null(value, fallback = null)
|
|
699
|
+
static null(value : any, fallback : any = null) : any
|
|
668
700
|
{
|
|
669
701
|
if ( value === 'null' ) {
|
|
670
702
|
return null;
|
|
@@ -685,13 +717,13 @@ export class PicoMixed
|
|
|
685
717
|
* @param {any} value Source value
|
|
686
718
|
* @returns {Array<any>} Array result
|
|
687
719
|
*/
|
|
688
|
-
static arr(value)
|
|
720
|
+
static arr(value : any) : Array<any>
|
|
689
721
|
{
|
|
690
722
|
if ( this.isArr(value) ) {
|
|
691
723
|
return value;
|
|
692
724
|
}
|
|
693
725
|
|
|
694
|
-
if ( !
|
|
726
|
+
if ( !this.isStr(value) ) {
|
|
695
727
|
return [value];
|
|
696
728
|
}
|
|
697
729
|
|
|
@@ -719,7 +751,7 @@ export class PicoMixed
|
|
|
719
751
|
* @param {any} value The value to convert
|
|
720
752
|
* @returns {string} Return value as string
|
|
721
753
|
*/
|
|
722
|
-
static str(value)
|
|
754
|
+
static str(value : any) : string
|
|
723
755
|
{
|
|
724
756
|
if ( this.isNix(value) ) {
|
|
725
757
|
return String(value);
|
|
@@ -747,9 +779,9 @@ export class PicoMixed
|
|
|
747
779
|
*
|
|
748
780
|
* @param {any} value The value to convert
|
|
749
781
|
* @param {any} fallback Fallback incase it is not primitive
|
|
750
|
-
* @returns {number
|
|
782
|
+
* @returns {number} Return value as number
|
|
751
783
|
*/
|
|
752
|
-
static num(value, fallback = NaN)
|
|
784
|
+
static num(value : any, fallback : number = NaN) : number
|
|
753
785
|
{
|
|
754
786
|
if ( !this.isPrim(value) ) {
|
|
755
787
|
return fallback;
|
|
@@ -776,10 +808,10 @@ export class PicoMixed
|
|
|
776
808
|
* @example Mix.int(true) // => NaN
|
|
777
809
|
*
|
|
778
810
|
* @param {any} value The value to convert
|
|
779
|
-
* @param {
|
|
780
|
-
* @returns {number
|
|
811
|
+
* @param {number} fallback Fallback incase it is not primitive
|
|
812
|
+
* @returns {number} Return value as integer
|
|
781
813
|
*/
|
|
782
|
-
static int(value, fallback = NaN)
|
|
814
|
+
static int(value : any, fallback : number = NaN) : number
|
|
783
815
|
{
|
|
784
816
|
if ( !this.isPrim(value) ) {
|
|
785
817
|
return fallback;
|
|
@@ -811,7 +843,7 @@ export class PicoMixed
|
|
|
811
843
|
* @param {any} value The value to convert
|
|
812
844
|
* @returns {boolean} Return value as boolean
|
|
813
845
|
*/
|
|
814
|
-
static bool(value)
|
|
846
|
+
static bool(value : any) : boolean
|
|
815
847
|
{
|
|
816
848
|
if ( this.isRef(value) ) {
|
|
817
849
|
return !!this.vals(value).length;
|
|
@@ -830,66 +862,77 @@ export class PicoMixed
|
|
|
830
862
|
static boolean = PicoMixed.bool;
|
|
831
863
|
}
|
|
832
864
|
|
|
833
|
-
|
|
865
|
+
// @ts-ignore
|
|
866
|
+
PicoMixed.global = function (...args : Parameters<typeof go>) {
|
|
834
867
|
console.warn('Mix.global() is deprecated, use go() instead.');
|
|
835
868
|
return go(...args);
|
|
836
869
|
};
|
|
837
870
|
|
|
838
|
-
|
|
871
|
+
// @ts-ignore
|
|
872
|
+
PicoMixed.isPlain = function (...args : Parameters<typeof Mix.isObj>) {
|
|
839
873
|
console.warn('Mix.isPlain() is deprecated, use Mix.isObj() instead.');
|
|
840
874
|
return Mix.isObj(...args);
|
|
841
875
|
};
|
|
842
876
|
|
|
843
|
-
|
|
877
|
+
// @ts-ignore
|
|
878
|
+
PicoMixed.float = function (...args : Parameters<typeof Mix.num>) {
|
|
844
879
|
console.warn('Mix.float() is deprecated, use Mix.num() instead.');
|
|
845
880
|
return Mix.num(...args);
|
|
846
881
|
};
|
|
847
882
|
|
|
848
|
-
|
|
883
|
+
// @ts-ignore
|
|
884
|
+
PicoMixed.delay = function (...args : Parameters<typeof Run.delay>) {
|
|
849
885
|
console.warn('Mix.delay() is deprecated, use Run.delay() instead.');
|
|
850
886
|
return Run.delay(...args);
|
|
851
887
|
};
|
|
852
888
|
|
|
853
|
-
|
|
889
|
+
// @ts-ignore
|
|
890
|
+
PicoMixed.async = function (...args : Parameters<typeof Run.async>) {
|
|
854
891
|
console.warn('Mix.async() is deprecated, use Run.async() instead.');
|
|
855
892
|
return Run.async(...args);
|
|
856
893
|
};
|
|
857
894
|
|
|
858
|
-
|
|
895
|
+
// @ts-ignore
|
|
896
|
+
PicoMixed.debounce = function (...args : Parameters<typeof Run.debounce>) {
|
|
859
897
|
console.warn('Mix.debounce() is deprecated, use Run.debounce() instead.');
|
|
860
898
|
return Run.debounce(...args);
|
|
861
899
|
};
|
|
862
900
|
|
|
863
|
-
|
|
901
|
+
// @ts-ignore
|
|
902
|
+
PicoMixed.throttle = function (...args : Parameters<typeof Run.throttle>) {
|
|
864
903
|
console.warn('Mix.throttle() is deprecated, use Run.throttle() instead.');
|
|
865
904
|
return Run.throttle(...args);
|
|
866
905
|
};
|
|
867
906
|
|
|
868
|
-
|
|
907
|
+
// @ts-ignore
|
|
908
|
+
PicoMixed.framerate = function (...args : Parameters<typeof Run.framerate>) {
|
|
869
909
|
console.warn('Mix.framerate() is deprecated, use Run.framerate() instead.');
|
|
870
910
|
return Run.framerate(...args);
|
|
871
911
|
};
|
|
872
912
|
|
|
873
|
-
|
|
913
|
+
// @ts-ignore
|
|
914
|
+
PicoMixed.convertString = function (...args : Parameters<typeof Str.string>) {
|
|
874
915
|
console.warn('Mix.convertString() is deprecated, use Str.string() instead.');
|
|
875
916
|
return Str.string(...args);
|
|
876
917
|
};
|
|
877
918
|
|
|
878
|
-
|
|
919
|
+
// @ts-ignore
|
|
920
|
+
PicoMixed.convertDatetime = function (...args : Parameters<typeof Str.date>) {
|
|
879
921
|
console.warn('Mix.convertDatetime() is deprecated, use Str.date() instead.');
|
|
880
922
|
return Str.date(...args);
|
|
881
923
|
};
|
|
882
924
|
|
|
883
|
-
|
|
925
|
+
// @ts-ignore
|
|
926
|
+
PicoMixed.convertBool = function (...args : Parameters<typeof Str.boolean>) {
|
|
884
927
|
console.warn('Mix.convertBool() is deprecated, use Str.boolean() instead.');
|
|
885
928
|
return Str.boolean(...args);
|
|
886
929
|
};
|
|
887
930
|
|
|
888
|
-
|
|
931
|
+
// @ts-ignore
|
|
932
|
+
PicoMixed.convertBoolean = function (...args : Parameters<typeof Str.boolean>) {
|
|
889
933
|
console.warn('Mix.convertBoolean() is deprecated, use Str.boolean() instead.');
|
|
890
934
|
return Str.boolean(...args);
|
|
891
935
|
};
|
|
892
936
|
|
|
893
937
|
|
|
894
|
-
|
|
895
938
|
export default PicoMixed;
|