@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.
Files changed (97) hide show
  1. package/dist/pico-js.browser.js +1 -1
  2. package/dist/pico-js.browser.js.map +1 -1
  3. package/dist/pico-js.esm.js +1 -1
  4. package/dist/pico-js.esm.js.map +1 -1
  5. package/package.json +4 -6
  6. package/src/dom/{DomAttribute.js → DomAttribute.ts} +40 -63
  7. package/src/dom/{DomBuilder.js → DomBuilder.ts} +27 -44
  8. package/src/dom/{DomEvent.js → DomEvent.ts} +101 -76
  9. package/src/dom/{DomFinder.js → DomFinder.ts} +103 -139
  10. package/src/dom/DomForm.ts +38 -0
  11. package/src/dom/{DomGlobal.js → DomGlobal.ts} +34 -51
  12. package/src/dom/{DomInview.js → DomInview.ts} +37 -57
  13. package/src/dom/DomMeta.ts +48 -0
  14. package/src/dom/DomObserver.ts +17 -0
  15. package/src/dom/{DomPopover.js → DomPopover.ts} +20 -39
  16. package/src/dom/{DomRectangle.js → DomRectangle.ts} +70 -87
  17. package/src/format/{FormatFile.js → FormatFile.ts} +12 -23
  18. package/src/format/{FormatOption.js → FormatOption.ts} +15 -24
  19. package/src/format/{FormatParam.js → FormatParam.ts} +14 -25
  20. package/src/format/{FormatParser.js → FormatParser.ts} +29 -39
  21. package/src/format/{FormatUrl.js → FormatUrl.ts} +9 -21
  22. package/src/index.browser.ts +32 -0
  23. package/src/index.esm.ts +64 -0
  24. package/src/now/{NowDefault.js → NowDefault.ts} +86 -121
  25. package/src/now/{NowFormat.js → NowFormat.ts} +23 -28
  26. package/src/now/{NowGrid.js → NowGrid.ts} +41 -58
  27. package/src/now/{NowHuman.js → NowHuman.ts} +18 -27
  28. package/src/now/{NowMatch.js → NowMatch.ts} +22 -28
  29. package/src/now/{NowRange.js → NowRange.ts} +13 -22
  30. package/src/now/{NowWalker.js → NowWalker.ts} +65 -71
  31. package/src/tool/{scope.js → scope.ts} +41 -11
  32. package/src/utils/{Array.js → Array.ts} +187 -152
  33. package/src/utils/{Cookie.js → Cookie.ts} +15 -12
  34. package/src/utils/{Data.js → Data.ts} +17 -17
  35. package/src/utils/Dom.ts +204 -0
  36. package/src/utils/Format.ts +48 -0
  37. package/src/utils/{Hash.js → Hash.ts} +20 -20
  38. package/src/utils/{Locale.js → Locale.ts} +21 -21
  39. package/src/utils/{Mixed.js → Mixed.ts} +104 -61
  40. package/src/utils/{Now.js → Now.ts} +68 -69
  41. package/src/utils/{Number.js → Number.ts} +34 -36
  42. package/src/utils/{Object.js → Object.ts} +68 -122
  43. package/src/utils/{Route.js → Route.ts} +11 -9
  44. package/src/utils/{Runner.js → Runner.ts} +89 -77
  45. package/src/utils/{Signal.js → Signal.ts} +35 -22
  46. package/src/utils/{String.js → String.ts} +79 -69
  47. package/src/wip/{Element.js → Element.ts} +2 -2
  48. package/src/wip/{Map.js → Map.ts} +1 -1
  49. package/types/dom/DomAttribute.d.ts +16 -27
  50. package/types/dom/DomBuilder.d.ts +6 -9
  51. package/types/dom/DomEvent.d.ts +19 -24
  52. package/types/dom/DomFinder.d.ts +38 -61
  53. package/types/dom/DomForm.d.ts +7 -10
  54. package/types/dom/DomGlobal.d.ts +8 -15
  55. package/types/dom/DomInview.d.ts +9 -19
  56. package/types/dom/DomMeta.d.ts +9 -16
  57. package/types/dom/DomObserver.d.ts +4 -8
  58. package/types/dom/DomPopover.d.ts +8 -11
  59. package/types/dom/DomRectangle.d.ts +21 -35
  60. package/types/format/FormatFile.d.ts +5 -8
  61. package/types/format/FormatOption.d.ts +6 -8
  62. package/types/format/FormatParam.d.ts +6 -9
  63. package/types/format/FormatParser.d.ts +10 -18
  64. package/types/format/FormatUrl.d.ts +5 -8
  65. package/types/index.esm.d.ts +25 -37
  66. package/types/now/NowDefault.d.ts +30 -99
  67. package/types/now/NowFormat.d.ts +8 -21
  68. package/types/now/NowGrid.d.ts +24 -46
  69. package/types/now/NowHuman.d.ts +10 -11
  70. package/types/now/NowMatch.d.ts +6 -4
  71. package/types/now/NowRange.d.ts +5 -8
  72. package/types/now/NowWalker.d.ts +6 -4
  73. package/types/tool/scope.d.ts +11 -3
  74. package/types/utils/Array.d.ts +83 -101
  75. package/types/utils/Cookie.d.ts +11 -8
  76. package/types/utils/Data.d.ts +7 -7
  77. package/types/utils/Dom.d.ts +63 -96
  78. package/types/utils/Format.d.ts +15 -28
  79. package/types/utils/Hash.d.ts +21 -21
  80. package/types/utils/Locale.d.ts +9 -9
  81. package/types/utils/Mixed.d.ts +19 -32
  82. package/types/utils/Now.d.ts +51 -56
  83. package/types/utils/Number.d.ts +9 -20
  84. package/types/utils/Object.d.ts +21 -36
  85. package/types/utils/Route.d.ts +5 -2
  86. package/types/utils/Runner.d.ts +45 -38
  87. package/types/utils/Signal.d.ts +16 -16
  88. package/types/utils/String.d.ts +40 -76
  89. package/src/dom/DomForm.js +0 -59
  90. package/src/dom/DomMeta.js +0 -68
  91. package/src/dom/DomObserver.js +0 -38
  92. package/src/index.browser.js +0 -36
  93. package/src/index.esm.js +0 -80
  94. package/src/utils/Dom.js +0 -214
  95. package/src/utils/Format.js +0 -62
  96. package/types/wip/Element.d.ts +0 -119
  97. package/types/wip/Map.d.ts +0 -254
@@ -1,63 +1,77 @@
1
- import { Arr, Dom, Mix, Now, Num } from "../index.esm.js";
2
- import { PicoNowDefaultPlugin } from "../now/NowDefault.js";
3
- import { PicoNowFormatPlugin } from "../now/NowFormat.js";
4
- import { PicoNowMatchPlugin } from "../now/NowMatch.js";
5
- import { PicoNowGridPlugin } from "../now/NowGrid.js";
6
- import { PicoNowWalkerPlugin } from "../now/NowWalker.js";
7
- import { PicoNowRangePlugin } from "../now/NowRange.js";
8
- import { PicoNowHumanPlugin } from "../now/NowHuman.js";
1
+ import { trait } from "../tool/scope.ts";
2
+ import { Arr, Mix, Now } from "../index.esm.ts";
3
+ import { PicoNowDefault } from "../now/NowDefault.ts";
4
+ import { PicoNowFormat } from "../now/NowFormat.ts";
5
+ import { PicoNowMatch } from "../now/NowMatch.ts";
6
+ import { PicoNowGrid } from "../now/NowGrid.ts";
7
+ import { PicoNowWalker } from "../now/NowWalker.ts";
8
+ import { PicoNowRange } from "../now/NowRange.ts";
9
+ import { PicoNowHuman } from "../now/NowHuman.ts";
9
10
 
10
11
  export const PicoNowPlugins = [
11
- PicoNowDefaultPlugin,
12
- PicoNowFormatPlugin,
13
- PicoNowMatchPlugin,
14
- PicoNowGridPlugin,
15
- PicoNowWalkerPlugin,
16
- PicoNowRangePlugin,
17
- PicoNowHumanPlugin,
12
+ PicoNowDefault,
13
+ PicoNowFormat,
14
+ PicoNowMatch,
15
+ PicoNowGrid,
16
+ PicoNowWalker,
17
+ PicoNowRange,
18
+ PicoNowHuman,
18
19
  ];
19
20
 
21
+ export interface PicoNowInterface
22
+ {
23
+ value : Date;
24
+ input : any;
25
+ reset(config : any) : PicoNow;
26
+ clone() : PicoNow;
27
+ valid() : boolean;
28
+ toDate() : Date;
29
+ toUTC() : string;
30
+ }
31
+
32
+ export interface PicoNow extends PicoNowDefault,
33
+ PicoNowFormat,
34
+ PicoNowMatch,
35
+ PicoNowGrid,
36
+ PicoNowWalker,
37
+ PicoNowRange,
38
+ PicoNowHuman
39
+ {
40
+ //
41
+ }
42
+
20
43
  /**
21
44
  * @class PicoNow
22
- *
23
- * @typedef {import('../now/NowMatch.js').PicoNowMatchInstance} PicoNowMatchInstance
24
- * @typedef {import('../now/NowFormat.js').PicoNowFormatInstance} PicoNowFormatInstance
25
- * @typedef {import('../now/NowMatch.js').PicoNowMatchInstance} PicoNowMatchInstance
26
- * @typedef {import('../now/NowGrid.js').PicoNowGridInstance} PicoNowGridInstance
27
- * @typedef {import('../now/NowWalker.js').PicoNowWalkerInstance} PicoNowWalkerInstance
28
- * @typedef {import('../now/NowRange.js').PicoNowRangeInstance} PicoNowRangeInstance
29
- * @typedef {import('../now/NowHuman.js').PicoNowHumanInstance} PicoNowHumanInstance
30
- *
31
- * @extends PicoNowDefaultInstance
32
- * @extends PicoNowFormatInstance
33
- * @extends PicoNowMatchInstance
34
- * @extends PicoNowGridInstance
35
- * @extends PicoNowWalkerInstance
36
- * @extends PicoNowRangeInstance
37
- * @extends PicoNowHumanInstance
45
+ * @extends PicoNowDefault
46
+ * @extends PicoNowFormat
47
+ * @extends PicoNowMatch
48
+ * @extends PicoNowGrid
49
+ * @extends PicoNowWalker
50
+ * @extends PicoNowRange
51
+ * @extends PicoNowHuman
38
52
  */
39
- export class PicoNow
53
+ export class PicoNow extends trait(PicoNowPlugins)
40
54
  {
41
55
  /**
42
56
  * Init hooks for instance
43
57
  *
44
- * @type {Array<function>}
58
+ * @type {Function[]}
45
59
  */
46
- static init = [];
60
+ static init : Function[] = [];
47
61
 
48
62
  /**
49
63
  * Original input value
50
64
  *
51
65
  * @type {any}
52
66
  */
53
- input = null;
67
+ input : any = null;
54
68
 
55
69
  /**
56
70
  * Current Date instance
57
71
  *
58
72
  * @type {Date}
59
73
  */
60
- value = null;
74
+ value : Date = null;
61
75
 
62
76
  /**
63
77
  * Create Now instance from input
@@ -67,8 +81,10 @@ export class PicoNow
67
81
  * @param {any} [value] Date input
68
82
  * @param {string} [format] Input format
69
83
  */
70
- constructor(value = null, format = 'YYYY-MM-DD HH:mm:ss')
84
+ constructor(value : any = null, format : string = 'YYYY-MM-DD HH:mm:ss')
71
85
  {
86
+ super();
87
+
72
88
  if ( value === 'now' ) {
73
89
  value = null;
74
90
  }
@@ -79,7 +95,7 @@ export class PicoNow
79
95
  value = value.toDate();
80
96
  }
81
97
 
82
- if ( ! (value instanceof Date) ) {
98
+ if ( !(value instanceof Date) ) {
83
99
  value = new Date();
84
100
  }
85
101
 
@@ -95,8 +111,8 @@ export class PicoNow
95
111
  this.parse(input, format);
96
112
  }
97
113
 
98
- Arr.each(Now.init, (fn) => {
99
- el = fn.call(this, el, format);
114
+ Arr.each(Now.init, (fn : Function) => {
115
+ fn.call(this, format);
100
116
  });
101
117
 
102
118
  return this;
@@ -107,10 +123,10 @@ export class PicoNow
107
123
  *
108
124
  * @example Now.extend(fn)
109
125
  *
110
- * @param {function} plugin Plugin function
126
+ * @param {Function} plugin Plugin function
111
127
  * @returns {void} No return value
112
128
  */
113
- static extend(plugin)
129
+ static extend(plugin : Function) : void
114
130
  {
115
131
  plugin.call({}, this);
116
132
  }
@@ -124,7 +140,7 @@ export class PicoNow
124
140
  * @param {string} [format] Input format
125
141
  * @returns {PicoNow} Now instance
126
142
  */
127
- static make(value = null, format = 'YYYY-MM-DD HH:mm:ss')
143
+ static make(value : any = null, format : string = 'YYYY-MM-DD HH:mm:ss') : PicoNow
128
144
  {
129
145
  return new Now(value, format);
130
146
  }
@@ -137,7 +153,7 @@ export class PicoNow
137
153
  * @param {any} [config] Reset flags
138
154
  * @returns {PicoNow} Now instance
139
155
  */
140
- reset(config = null)
156
+ reset(config : any = null) : PicoNow
141
157
  {
142
158
  if ( config == null ) {
143
159
  config = { month: true, day: true, time: true };
@@ -163,12 +179,11 @@ export class PicoNow
163
179
  *
164
180
  * @example Now.make().clone() // => Now
165
181
  *
166
- * @param {boolean} [reset] Reset clone
167
182
  * @returns {PicoNow} New instance
168
183
  */
169
- clone(reset = false)
184
+ clone() : PicoNow
170
185
  {
171
- return new Now(new Date(this.value), null, reset);
186
+ return new Now(new Date(this.value), null);
172
187
  }
173
188
 
174
189
  /**
@@ -178,9 +193,9 @@ export class PicoNow
178
193
  *
179
194
  * @returns {boolean} True if valid
180
195
  */
181
- valid()
196
+ valid() : boolean
182
197
  {
183
- return ! isNaN(this.input);
198
+ return !isNaN(this.input);
184
199
  }
185
200
 
186
201
  /**
@@ -190,7 +205,7 @@ export class PicoNow
190
205
  *
191
206
  * @returns {Date} Date instance
192
207
  */
193
- toDate()
208
+ toDate() : Date
194
209
  {
195
210
  return this.value;
196
211
  }
@@ -202,33 +217,17 @@ export class PicoNow
202
217
  *
203
218
  * @returns {string} UTC string
204
219
  */
205
- toUTC()
220
+ toUTC() : string
206
221
  {
207
222
  return this.value.toUTCString();
208
223
  }
209
224
 
210
225
  }
211
226
 
212
- /**
213
- * @see PicoNow.reset
214
- */
227
+ // @ts-ignore
215
228
  PicoNow.prototype.resetTime = function () {
216
229
  console.warn('Now.resetTime() is deprecated, use Now.reset({ time: true }) instead.');
217
230
  return this.reset({ time: true });
218
231
  }
219
232
 
220
- /**
221
- * @returns {typeof PicoNow}
222
- */
223
- export function PicoNowBuilder() {
224
-
225
- let cls = PicoNow;
226
-
227
- for ( const plugin of PicoNowPlugins ) {
228
- cls = plugin.call(cls, cls);
229
- }
230
-
231
- return cls;
232
- }
233
-
234
- export default PicoNowBuilder;
233
+ export default PicoNow;
@@ -1,8 +1,7 @@
1
- import { Mix, Num, Arr, Hash, Str, Obj } from "../index.esm.js";
1
+ import { Mix, Arr, Hash, Str } from "../index.esm.ts";
2
2
 
3
3
  export class PicoNumber
4
4
  {
5
-
6
5
  /**
7
6
  * Format number with decimals
8
7
  *
@@ -13,9 +12,9 @@ export class PicoNumber
13
12
  * @param {number} decimals Decimals count
14
13
  * @returns {string} Fixed string
15
14
  */
16
- static fixed(value, decimals = 2)
15
+ static fixed(value : any, decimals : number = 2) : string
17
16
  {
18
- if ( ! Mix.isNum(value) ) {
17
+ if ( !Mix.isNum(value) ) {
19
18
  value = Mix.num(value);
20
19
  }
21
20
 
@@ -31,9 +30,9 @@ export class PicoNumber
31
30
  * @param {any} value Numeric value
32
31
  * @returns {number} Parsed float
33
32
  */
34
- static float(value)
33
+ static float(value : any) : number
35
34
  {
36
- if ( ! Mix.isNum(value) ) {
35
+ if ( !Mix.isNum(value) ) {
37
36
  value = Mix.num(value);
38
37
  }
39
38
 
@@ -49,9 +48,9 @@ export class PicoNumber
49
48
  * @param {any} value Numeric value
50
49
  * @returns {number} Parsed int
51
50
  */
52
- static int(value)
51
+ static int(value : any) : number
53
52
  {
54
- if ( ! Mix.isNum(value) ) {
53
+ if ( !Mix.isNum(value) ) {
55
54
  value = Mix.num(value);
56
55
  }
57
56
 
@@ -67,9 +66,9 @@ export class PicoNumber
67
66
  * @param {any} value Numeric value
68
67
  * @returns {number} Ceil value
69
68
  */
70
- static ceil(value)
69
+ static ceil(value : any) : number
71
70
  {
72
- if ( ! Mix.isNum(value) ) {
71
+ if ( !Mix.isNum(value) ) {
73
72
  value = Mix.num(value);
74
73
  }
75
74
 
@@ -85,9 +84,9 @@ export class PicoNumber
85
84
  * @param {any} value Numeric value
86
85
  * @returns {number} Floor value
87
86
  */
88
- static floor(value)
87
+ static floor(value : any) : number
89
88
  {
90
- if ( ! Mix.isNum(value) ) {
89
+ if ( !Mix.isNum(value) ) {
91
90
  value = Mix.num(value);
92
91
  }
93
92
 
@@ -103,9 +102,9 @@ export class PicoNumber
103
102
  * @param {any} value Numeric value
104
103
  * @returns {number} Rounded value
105
104
  */
106
- static round(value)
105
+ static round(value : any) : number
107
106
  {
108
- if ( ! Mix.isNum(value) ) {
107
+ if ( !Mix.isNum(value) ) {
109
108
  value = Mix.num(value);
110
109
  }
111
110
 
@@ -118,12 +117,12 @@ export class PicoNumber
118
117
  * @example Num.combine([1, 2]) // => 3
119
118
  * @example Num.combine([5, -2]) // => 3
120
119
  *
121
- * @param {Array<number>} value Number list
120
+ * @param {number[]} value Number list
122
121
  * @returns {number} Sum value
123
122
  */
124
- static combine(value)
123
+ static combine(value : number[]) : number
125
124
  {
126
- return Arr.reduce(value, (acc, val) => acc + val, 0);
125
+ return Arr.reduce(value, (acc : number, val : any) => acc + val, 0);
127
126
  }
128
127
 
129
128
  /**
@@ -132,12 +131,12 @@ export class PicoNumber
132
131
  * @example Num.subtract([5, 2]) // => 3
133
132
  * @example Num.subtract([10, 3]) // => 7
134
133
  *
135
- * @param {Array<number>} value Number list
134
+ * @param {number[]} value Number list
136
135
  * @returns {number} Result value
137
136
  */
138
- static subtract(value)
137
+ static subtract(value : number[]) : number
139
138
  {
140
- return Arr.reduce(value, (acc, val) => acc - val, 0);
139
+ return Arr.reduce(value, (acc : number, val : any) => acc - val, 0);
141
140
  }
142
141
 
143
142
  /**
@@ -149,9 +148,9 @@ export class PicoNumber
149
148
  * @param {any} value Numeric value
150
149
  * @returns {number} Decade value
151
150
  */
152
- static decade(value)
151
+ static decade(value : any) : number
153
152
  {
154
- if ( ! Mix.isNum(value) ) {
153
+ if ( !Mix.isNum(value) ) {
155
154
  value = Mix.num(value);
156
155
  }
157
156
 
@@ -164,16 +163,19 @@ export class PicoNumber
164
163
  * @example Num.matrix(5) // => [4, 1]
165
164
  * @example Num.matrix(8) // => [8]
166
165
  *
167
- * @param {number} num Input number
168
- * @param {number} [limit] Unused (legacy)
169
- * @param {Array<number>} [base] Result base
166
+ * @param {any} num Input number
167
+ * @param {number[]} [base] Result base
170
168
  * @returns {Array<number>} Power list
171
169
  */
172
- static matrix(num, limit = 10, base = [])
170
+ static matrix(num : any, base : number[] = []) : Array<number>
173
171
  {
172
+ if ( !Mix.isNum(num) ) {
173
+ num = Mix.num(num);
174
+ }
175
+
174
176
  let value = 0;
175
177
 
176
- for ( let i = 20; i >= 0; i -- ) {
178
+ for ( let i = 20; i >= 0; i-- ) {
177
179
  if ( num >= (value = Math.pow(2, i)) ) {
178
180
  (base.push(value), num -= value);
179
181
  }
@@ -192,7 +194,7 @@ export class PicoNumber
192
194
  * @param {boolean} [miles] Return miles if true
193
195
  * @returns {number} Distance value
194
196
  */
195
- static distance(cord1, cord2, miles = false)
197
+ static distance(cord1 : any, cord2 : any, miles : boolean = false) : number
196
198
  {
197
199
  let cord = { lat: 0, lng: 0 };
198
200
 
@@ -219,18 +221,14 @@ export class PicoNumber
219
221
 
220
222
  }
221
223
 
222
- /**
223
- * @see PicoStr.number
224
- */
225
- PicoNumber.format = (value, ...args) => {
224
+ // @ts-ignore
225
+ PicoNumber.format = (value : any, ...args : [any, any, any]) => {
226
226
  console.warn('Num.format() is deprecated, use Str.number() instead.');
227
227
  return Str.number(value, args[2] || null);
228
228
  };
229
229
 
230
- /**
231
- * @see PicoHash.number
232
- */
233
- PicoNumber.random = (...args) => {
230
+ // @ts-ignore
231
+ PicoNumber.random = (...args : Parameters<typeof Hash.number>) => {
234
232
  console.warn('Num.random() is deprecated, use Hash.number() instead.');
235
233
  return Hash.number(...args);
236
234
  };