@kizmann/pico-js 2.0.12 → 2.1.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/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 +1 -1
- package/src/index.esm.ts +5 -5
- package/src/now/NowDefault.ts +67 -4
- package/src/now/NowDuration.ts +122 -0
- package/src/now/NowFormat.ts +1 -0
- package/src/now/NowGrid.ts +25 -25
- package/src/now/NowHuman.ts +2 -2
- package/src/utils/Array.ts +1 -1
- package/src/utils/Dom.ts +36 -0
- package/src/utils/Format.ts +7 -0
- package/src/utils/Hash.ts +20 -1
- package/src/utils/Now.ts +6 -3
- package/src/utils/Number.ts +14 -2
- package/src/utils/Runner.ts +8 -2
- package/src/utils/String.ts +4 -0
- package/types/index.esm.d.ts +3 -0
- package/types/now/NowDefault.d.ts +1 -1
- package/types/now/NowDuration.d.ts +38 -0
- package/types/now/NowGrid.d.ts +19 -19
- package/types/utils/Dom.d.ts +27 -0
- package/types/utils/Format.d.ts +7 -0
- package/types/utils/Hash.d.ts +9 -0
- package/types/utils/Now.d.ts +3 -3
- package/types/wip/Element.d.ts +119 -0
- package/types/wip/Map.d.ts +281 -0
package/package.json
CHANGED
package/src/index.esm.ts
CHANGED
|
@@ -28,12 +28,12 @@ export {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// Work in progress (not started yet)
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
import { default as Map } from "./wip/Map.ts";
|
|
32
|
+
import { default as Element } from "./wip/Element.ts";
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
export {
|
|
35
|
+
Map, Element
|
|
36
|
+
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* @type {Mix}
|
package/src/now/NowDefault.ts
CHANGED
|
@@ -20,11 +20,36 @@ export interface PicoNowDefault extends PicoNowInterface
|
|
|
20
20
|
*/
|
|
21
21
|
export class PicoNowDefault
|
|
22
22
|
{
|
|
23
|
-
|
|
23
|
+
calc(value : any, scope : string) : PicoNow
|
|
24
24
|
{
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
if ( ! Mix.isNum(value) ) {
|
|
26
|
+
value = Mix.int(value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let result = 0;
|
|
30
|
+
|
|
31
|
+
if ( /^seconds?$/i.test(scope) ) {
|
|
32
|
+
result = value * 1000;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if ( /^minutes?$/i.test(scope) ) {
|
|
36
|
+
result = value * 1000 * 60;
|
|
37
|
+
}
|
|
27
38
|
|
|
39
|
+
if ( /^hours?$/i.test(scope) ) {
|
|
40
|
+
result = value * 1000 * 60 * 60;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if ( /^dates?$/i.test(scope) ) {
|
|
44
|
+
result = value * 1000 * 60 * 60 * 24;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
this.value.setTime(...[
|
|
48
|
+
this.value.getTime() + result
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
return <PicoNow> <unknown> this;
|
|
52
|
+
}
|
|
28
53
|
/**
|
|
29
54
|
* Get value by scope
|
|
30
55
|
*
|
|
@@ -81,6 +106,10 @@ export class PicoNowDefault
|
|
|
81
106
|
*/
|
|
82
107
|
set(value : any, scope : string) : PicoNow
|
|
83
108
|
{
|
|
109
|
+
if ( value == null) {
|
|
110
|
+
return <PicoNow> <unknown> this;
|
|
111
|
+
}
|
|
112
|
+
|
|
84
113
|
if ( !Mix.isNum(value) ) {
|
|
85
114
|
value = Mix.int(value);
|
|
86
115
|
}
|
|
@@ -289,6 +318,22 @@ export class PicoNowDefault
|
|
|
289
318
|
scope = 'date';
|
|
290
319
|
}
|
|
291
320
|
|
|
321
|
+
if ( /^seconds?$/i.test(scope) ) {
|
|
322
|
+
return this.calc(value, scope);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if ( /^minutes?$/i.test(scope) ) {
|
|
326
|
+
return this.calc(value, scope);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if ( /^hours?$/i.test(scope) ) {
|
|
330
|
+
return this.calc(value, scope);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if ( /^dates?$/i.test(scope) ) {
|
|
334
|
+
return this.calc(value, scope);
|
|
335
|
+
}
|
|
336
|
+
|
|
292
337
|
this.set(this.get(scope) + Mix.int(value), scope);
|
|
293
338
|
|
|
294
339
|
return <PicoNow> <unknown> this;
|
|
@@ -309,7 +354,25 @@ export class PicoNowDefault
|
|
|
309
354
|
scope = 'date';
|
|
310
355
|
}
|
|
311
356
|
|
|
312
|
-
|
|
357
|
+
if ( /^seconds?$/i.test(scope) ) {
|
|
358
|
+
return this.calc(value * -1, scope);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if ( /^minutes?$/i.test(scope) ) {
|
|
362
|
+
return this.calc(value * -1, scope);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if ( /^hours?$/i.test(scope) ) {
|
|
366
|
+
return this.calc(value * -1, scope);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if ( /^dates?$/i.test(scope) ) {
|
|
370
|
+
return this.calc(value * -1, scope);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
this.set(...[
|
|
374
|
+
this.get(scope) - Mix.int(value), scope
|
|
375
|
+
]);
|
|
313
376
|
|
|
314
377
|
return <PicoNow> <unknown> this;
|
|
315
378
|
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Arr, Mix, Now, Obj, Str } from "../index.esm.ts";
|
|
2
|
+
import { PicoNow, PicoNowInterface } from "../utils/Now.ts";
|
|
3
|
+
import PicoNowDefault from "./NowDefault.ts";
|
|
4
|
+
import PicoNowFormat from "./NowFormat.ts";
|
|
5
|
+
|
|
6
|
+
export interface PicoNowDuration extends PicoNowInterface,
|
|
7
|
+
PicoNowDefault,
|
|
8
|
+
PicoNowFormat
|
|
9
|
+
{
|
|
10
|
+
//
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @memberof PicoNow
|
|
15
|
+
*/
|
|
16
|
+
export class PicoNowDuration
|
|
17
|
+
{
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Calculate duration between two dates
|
|
21
|
+
*
|
|
22
|
+
* @example Now.make("2026-01-01").duration("2026-02-01") // => { years: 0, months: 1, ... }
|
|
23
|
+
*
|
|
24
|
+
* @param {any} value End date
|
|
25
|
+
* @returns {any} Duration object
|
|
26
|
+
*/
|
|
27
|
+
duration(value : any) : any
|
|
28
|
+
{
|
|
29
|
+
if ( Mix.isNum(value) ) {
|
|
30
|
+
value = this.clone().add(value, 'seconds');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const date = Now.make(value);
|
|
34
|
+
|
|
35
|
+
const keys = [
|
|
36
|
+
'years', 'months', 'dates', 'hours', 'minutes', 'seconds'
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
let result : any = {};
|
|
40
|
+
|
|
41
|
+
Arr.each(keys, (key : string) => {
|
|
42
|
+
result[key] = date.get(key) - this.get(key);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const last = date.clone().sub(1, 'month')
|
|
46
|
+
.last('date').date();
|
|
47
|
+
|
|
48
|
+
if ( result.minutes && result.seconds < 0 ) {
|
|
49
|
+
result.minutes -= 1, result.seconds += 60;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if ( result.hours && result.minutes < 0 ) {
|
|
53
|
+
result.hours -= 1, result.minutes += 60;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if ( result.dates && result.hours < 0 ) {
|
|
57
|
+
result.dates -= 1, result.hours += 24;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if ( result.months && result.dates < 0 ) {
|
|
61
|
+
result.months -= 1, result.dates += last;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if ( result.years && result.months < 0 ) {
|
|
65
|
+
result.years -= 1, result.months += 12;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Normalize seconds into duration parts
|
|
73
|
+
*
|
|
74
|
+
* @example Now.make().safeDuration(3661) // => { dates: 0, hours: 1, minutes: 1, seconds: 1 }
|
|
75
|
+
*
|
|
76
|
+
* @param {number} value Seconds value
|
|
77
|
+
* @returns {any} Duration object
|
|
78
|
+
*/
|
|
79
|
+
safeDuration(value : number) : any
|
|
80
|
+
{
|
|
81
|
+
let result : any = {
|
|
82
|
+
dates: 0,
|
|
83
|
+
hours: 0,
|
|
84
|
+
minutes: 0,
|
|
85
|
+
seconds: Mix.int(value)
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
if ( result.seconds >= 60 ) {
|
|
89
|
+
result.minutes = Math.floor(result.seconds / 60);
|
|
90
|
+
result.seconds %= 60;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if ( result.minutes >= 60 ) {
|
|
94
|
+
result.hours = Math.floor(result.minutes / 60);
|
|
95
|
+
result.minutes %= 60;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if ( result.hours >= 24 ) {
|
|
99
|
+
result.dates = Math.floor(result.hours / 24);
|
|
100
|
+
result.hours %= 24;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get difference between two dates in seconds
|
|
108
|
+
*
|
|
109
|
+
* @example Now.make("2026-01-02").diffrence("2026-01-01") // => 86400
|
|
110
|
+
*
|
|
111
|
+
* @param {any} [value=null] Compare date
|
|
112
|
+
* @returns {number} Seconds difference
|
|
113
|
+
*/
|
|
114
|
+
diffrence(value : any = null) : number
|
|
115
|
+
{
|
|
116
|
+
return this.code('x') - Now.make(value).code('x');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
export default PicoNowDuration;
|
package/src/now/NowFormat.ts
CHANGED
package/src/now/NowGrid.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Arr } from "../index.esm.ts";
|
|
2
|
-
import { PicoNowInterface } from "../utils/Now.ts";
|
|
2
|
+
import { PicoNow, PicoNowInterface } from "../utils/Now.ts";
|
|
3
3
|
import PicoNowWalker from "./NowWalker.js";
|
|
4
4
|
|
|
5
5
|
export interface PicoNowGrid extends PicoNowInterface,
|
|
@@ -19,9 +19,9 @@ export class PicoNowGrid
|
|
|
19
19
|
* @example Now.grid("month") // => [Now, Now, ...]
|
|
20
20
|
*
|
|
21
21
|
* @param {string} [scope] Grid scope
|
|
22
|
-
* @returns {Array<
|
|
22
|
+
* @returns {Array<PicoNow>} Array of dates
|
|
23
23
|
*/
|
|
24
|
-
grid(scope : string = 'day') : Array<
|
|
24
|
+
grid(scope : string = 'day') : Array<PicoNow>
|
|
25
25
|
{
|
|
26
26
|
if ( /^seconds?$/i.test(scope) ) {
|
|
27
27
|
return this.getSecondsGrid();
|
|
@@ -64,9 +64,9 @@ export class PicoNowGrid
|
|
|
64
64
|
* @example Now.getSecondsGrid(10)
|
|
65
65
|
*
|
|
66
66
|
* @param {number} [interval] Step interval
|
|
67
|
-
* @returns {Array<
|
|
67
|
+
* @returns {Array<PicoNow>} Array of dates
|
|
68
68
|
*/
|
|
69
|
-
getSecondsGrid(interval : number = 1) : Array<
|
|
69
|
+
getSecondsGrid(interval : number = 1) : Array<PicoNow>
|
|
70
70
|
{
|
|
71
71
|
if ( interval == null ) {
|
|
72
72
|
interval = 1;
|
|
@@ -83,9 +83,9 @@ export class PicoNowGrid
|
|
|
83
83
|
* @example Now.getMinutesGrid(10)
|
|
84
84
|
*
|
|
85
85
|
* @param {number} [interval] Step interval
|
|
86
|
-
* @returns {Array<
|
|
86
|
+
* @returns {Array<PicoNow>} Array of dates
|
|
87
87
|
*/
|
|
88
|
-
getMinutesGrid(interval : number = 1) : Array<
|
|
88
|
+
getMinutesGrid(interval : number = 1) : Array<PicoNow>
|
|
89
89
|
{
|
|
90
90
|
if ( interval == null ) {
|
|
91
91
|
interval = 1;
|
|
@@ -102,9 +102,9 @@ export class PicoNowGrid
|
|
|
102
102
|
* @example Now.getHoursGrid(2)
|
|
103
103
|
*
|
|
104
104
|
* @param {number} [interval] Step interval
|
|
105
|
-
* @returns {Array<
|
|
105
|
+
* @returns {Array<PicoNow>} Array of dates
|
|
106
106
|
*/
|
|
107
|
-
getHoursGrid(interval : number = 1) : Array<
|
|
107
|
+
getHoursGrid(interval : number = 1) : Array<PicoNow>
|
|
108
108
|
{
|
|
109
109
|
if ( interval == null ) {
|
|
110
110
|
interval = 1;
|
|
@@ -120,9 +120,9 @@ export class PicoNowGrid
|
|
|
120
120
|
*
|
|
121
121
|
* @example Now.getDaysGrid()
|
|
122
122
|
*
|
|
123
|
-
* @returns {Array<
|
|
123
|
+
* @returns {Array<PicoNow>} Array of dates
|
|
124
124
|
*/
|
|
125
|
-
getDaysGrid() : Array<
|
|
125
|
+
getDaysGrid() : Array<PicoNow>
|
|
126
126
|
{
|
|
127
127
|
let dates = [
|
|
128
128
|
this.first('date').first('day'), this.last('date').last('day')
|
|
@@ -136,9 +136,9 @@ export class PicoNowGrid
|
|
|
136
136
|
*
|
|
137
137
|
* @example Now.getDatesGrid()
|
|
138
138
|
*
|
|
139
|
-
* @returns {Array<
|
|
139
|
+
* @returns {Array<PicoNow>} Array of dates
|
|
140
140
|
*/
|
|
141
|
-
getDatesGrid() : Array<
|
|
141
|
+
getDatesGrid() : Array<PicoNow>
|
|
142
142
|
{
|
|
143
143
|
let dates = [
|
|
144
144
|
this.first('date'), this.last('date')
|
|
@@ -152,9 +152,9 @@ export class PicoNowGrid
|
|
|
152
152
|
*
|
|
153
153
|
* @example Now.getMonthsGrid()
|
|
154
154
|
*
|
|
155
|
-
* @returns {Array<
|
|
155
|
+
* @returns {Array<PicoNow>} Array of dates
|
|
156
156
|
*/
|
|
157
|
-
getMonthsGrid() : Array<
|
|
157
|
+
getMonthsGrid() : Array<PicoNow>
|
|
158
158
|
{
|
|
159
159
|
let dates = [
|
|
160
160
|
this.first('month'), this.last('month')
|
|
@@ -168,9 +168,9 @@ export class PicoNowGrid
|
|
|
168
168
|
*
|
|
169
169
|
* @example Now.getYearsGrid()
|
|
170
170
|
*
|
|
171
|
-
* @returns {Array<
|
|
171
|
+
* @returns {Array<PicoNow>} Array of dates
|
|
172
172
|
*/
|
|
173
|
-
getYearsGrid() : Array<
|
|
173
|
+
getYearsGrid() : Array<PicoNow>
|
|
174
174
|
{
|
|
175
175
|
let dates = [
|
|
176
176
|
this.first('year'), this.clone().last('year')
|
|
@@ -184,9 +184,9 @@ export class PicoNowGrid
|
|
|
184
184
|
*
|
|
185
185
|
* @example Now.getDecadesGrid()
|
|
186
186
|
*
|
|
187
|
-
* @returns {Array<
|
|
187
|
+
* @returns {Array<PicoNow>} Array of dates
|
|
188
188
|
*/
|
|
189
|
-
getDecadesGrid() : Array<
|
|
189
|
+
getDecadesGrid() : Array<PicoNow>
|
|
190
190
|
{
|
|
191
191
|
let dates = [
|
|
192
192
|
this.first('decade'), this.clone().last('decade')
|
|
@@ -201,7 +201,7 @@ export class PicoNowGrid
|
|
|
201
201
|
* @deprecated use Now.grid instead
|
|
202
202
|
*/
|
|
203
203
|
// @ts-ignore
|
|
204
|
-
PicoNowGrid.prototype.getYears = function() : Array<
|
|
204
|
+
PicoNowGrid.prototype.getYears = function() : Array<PicoNow> {
|
|
205
205
|
console.warn('Now.getYears() is deprecated, use Now.grid(\'years\') instead.');
|
|
206
206
|
return this.grid('years');
|
|
207
207
|
};
|
|
@@ -210,7 +210,7 @@ PicoNowGrid.prototype.getYears = function() : Array<PicoNowInterface> {
|
|
|
210
210
|
* @deprecated use Now.grid instead
|
|
211
211
|
*/
|
|
212
212
|
// @ts-ignore
|
|
213
|
-
PicoNowGrid.prototype.getMonths = function() : Array<
|
|
213
|
+
PicoNowGrid.prototype.getMonths = function() : Array<PicoNow> {
|
|
214
214
|
console.warn('Now.getMonths() is deprecated, use Now.grid(\'months\') instead.');
|
|
215
215
|
return this.grid('months');
|
|
216
216
|
};
|
|
@@ -219,7 +219,7 @@ PicoNowGrid.prototype.getMonths = function() : Array<PicoNowInterface> {
|
|
|
219
219
|
* @deprecated use Now.grid instead
|
|
220
220
|
*/
|
|
221
221
|
// @ts-ignore
|
|
222
|
-
PicoNowGrid.prototype.getDates = function() : Array<
|
|
222
|
+
PicoNowGrid.prototype.getDates = function() : Array<PicoNow> {
|
|
223
223
|
console.warn('Now.getDates() is deprecated, use Now.grid(\'dates\') instead.');
|
|
224
224
|
return this.grid('dates');
|
|
225
225
|
};
|
|
@@ -228,7 +228,7 @@ PicoNowGrid.prototype.getDates = function() : Array<PicoNowInterface> {
|
|
|
228
228
|
* @deprecated use Now.grid instead
|
|
229
229
|
*/
|
|
230
230
|
// @ts-ignore
|
|
231
|
-
PicoNowGrid.prototype.getHours = function() : Array<
|
|
231
|
+
PicoNowGrid.prototype.getHours = function() : Array<PicoNow> {
|
|
232
232
|
console.warn('Now.getHours() is deprecated, use Now.grid(\'hours\') instead.');
|
|
233
233
|
return this.grid('hours');
|
|
234
234
|
};
|
|
@@ -237,7 +237,7 @@ PicoNowGrid.prototype.getHours = function() : Array<PicoNowInterface> {
|
|
|
237
237
|
* @deprecated use Now.grid instead
|
|
238
238
|
*/
|
|
239
239
|
// @ts-ignore
|
|
240
|
-
PicoNowGrid.prototype.getMinutes = function() : Array<
|
|
240
|
+
PicoNowGrid.prototype.getMinutes = function() : Array<PicoNow> {
|
|
241
241
|
console.warn('Now.getMinutes() is deprecated, use Now.grid(\'minutes\') instead.');
|
|
242
242
|
return this.grid('minutes');
|
|
243
243
|
};
|
|
@@ -246,7 +246,7 @@ PicoNowGrid.prototype.getMinutes = function() : Array<PicoNowInterface> {
|
|
|
246
246
|
* @deprecated use Now.grid instead
|
|
247
247
|
*/
|
|
248
248
|
// @ts-ignore
|
|
249
|
-
PicoNowGrid.prototype.getSeconds = function() : Array<
|
|
249
|
+
PicoNowGrid.prototype.getSeconds = function() : Array<PicoNow> {
|
|
250
250
|
console.warn('Now.getSeconds() is deprecated, use Now.grid(\'seconds\') instead.');
|
|
251
251
|
return this.grid('seconds');
|
|
252
252
|
};
|
package/src/now/NowHuman.ts
CHANGED
|
@@ -66,7 +66,7 @@ export class PicoNowHuman
|
|
|
66
66
|
*/
|
|
67
67
|
getHumanDay(substr : number = null) : string
|
|
68
68
|
{
|
|
69
|
-
let day = this.day()
|
|
69
|
+
let day = this.day();
|
|
70
70
|
|
|
71
71
|
if ( !NOW_HUMAN_DAYS[day] ) {
|
|
72
72
|
throw new Error(`Invalid day number "${day}".`);
|
|
@@ -91,7 +91,7 @@ export class PicoNowHuman
|
|
|
91
91
|
*/
|
|
92
92
|
getHumanMonth(substr : number = null) : string
|
|
93
93
|
{
|
|
94
|
-
let month = this.
|
|
94
|
+
let month = this.month() - 1;
|
|
95
95
|
|
|
96
96
|
if ( !NOW_HUMAN_MONTHS[month] ) {
|
|
97
97
|
throw new Error(`Invalid month number "${month}".`);
|
package/src/utils/Array.ts
CHANGED
package/src/utils/Dom.ts
CHANGED
|
@@ -28,11 +28,35 @@ export const PicoDomPlugins = [
|
|
|
28
28
|
|
|
29
29
|
export interface PicoDomInterface
|
|
30
30
|
{
|
|
31
|
+
/**
|
|
32
|
+
* @type {any}
|
|
33
|
+
*/
|
|
31
34
|
el: any;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @type {any[]}
|
|
38
|
+
*/
|
|
32
39
|
els: any[];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {Function} plugin
|
|
43
|
+
* @returns {void}
|
|
44
|
+
*/
|
|
33
45
|
extend(plugin : Function) : void;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @returns {any}
|
|
49
|
+
*/
|
|
34
50
|
win() : any;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @returns {any}
|
|
54
|
+
*/
|
|
35
55
|
doc() : any;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @returns {any}
|
|
59
|
+
*/
|
|
36
60
|
body() : any;
|
|
37
61
|
}
|
|
38
62
|
|
|
@@ -199,6 +223,18 @@ export class PicoDom extends trait(PicoDomPlugins)
|
|
|
199
223
|
return this.doc().body;
|
|
200
224
|
}
|
|
201
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Remove elements from DOM
|
|
228
|
+
*
|
|
229
|
+
* @example Dom.find("div").remove()
|
|
230
|
+
*
|
|
231
|
+
* @returns {void} No return value
|
|
232
|
+
*/
|
|
233
|
+
remove() : void
|
|
234
|
+
{
|
|
235
|
+
this.each((el : any) => el.remove());
|
|
236
|
+
}
|
|
237
|
+
|
|
202
238
|
}
|
|
203
239
|
|
|
204
240
|
export default PicoDom;
|
package/src/utils/Format.ts
CHANGED
|
@@ -27,6 +27,13 @@ export interface PicoFormat extends PicoFormatParser,
|
|
|
27
27
|
//
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* @class PicoFormat
|
|
32
|
+
* @extends PicoFormatParam
|
|
33
|
+
* @extends PicoFormatOption
|
|
34
|
+
* @extends PicoFormatUrl
|
|
35
|
+
* @extends PicoFormatFile
|
|
36
|
+
*/
|
|
30
37
|
export class PicoFormat extends trait(PicoFormatPlugins)
|
|
31
38
|
{
|
|
32
39
|
|
package/src/utils/Hash.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Str } from "../index.esm.ts";
|
|
1
|
+
import { Mix, Str } from "../index.esm.ts";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @var {string[]} RADIX_NUMBER Radix from 0 to 9
|
|
@@ -159,6 +159,25 @@ export class PicoHash
|
|
|
159
159
|
return hash;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
/**
|
|
163
|
+
* Get a numeric hash for object
|
|
164
|
+
*
|
|
165
|
+
* @example Hash.object({ a: 1 }) // => '8823432'
|
|
166
|
+
*
|
|
167
|
+
* @param {any} value Object to hash
|
|
168
|
+
* @returns {string} String numeric hash
|
|
169
|
+
*/
|
|
170
|
+
static object(value : any) : string
|
|
171
|
+
{
|
|
172
|
+
let conv = JSON.stringify(value), hash = 0;
|
|
173
|
+
|
|
174
|
+
for (let i = 0; i < conv.length; i++) {
|
|
175
|
+
hash = (hash << 5) - hash + conv.charCodeAt(i) | 0;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return Mix.str(hash).replace('-', 'X');
|
|
179
|
+
}
|
|
180
|
+
|
|
162
181
|
}
|
|
163
182
|
|
|
164
183
|
export default PicoHash;
|
package/src/utils/Now.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { PicoNowGrid } from "../now/NowGrid.ts";
|
|
|
7
7
|
import { PicoNowWalker } from "../now/NowWalker.ts";
|
|
8
8
|
import { PicoNowRange } from "../now/NowRange.ts";
|
|
9
9
|
import { PicoNowHuman } from "../now/NowHuman.ts";
|
|
10
|
+
import PicoNowDuration from "../now/NowDuration.ts";
|
|
10
11
|
|
|
11
12
|
export const PicoNowPlugins = [
|
|
12
13
|
PicoNowDefault,
|
|
@@ -16,6 +17,7 @@ export const PicoNowPlugins = [
|
|
|
16
17
|
PicoNowWalker,
|
|
17
18
|
PicoNowRange,
|
|
18
19
|
PicoNowHuman,
|
|
20
|
+
PicoNowDuration,
|
|
19
21
|
];
|
|
20
22
|
|
|
21
23
|
export interface PicoNowInterface
|
|
@@ -62,9 +64,9 @@ export class PicoNow extends trait(PicoNowPlugins)
|
|
|
62
64
|
/**
|
|
63
65
|
* Original input value
|
|
64
66
|
*
|
|
65
|
-
* @type {
|
|
67
|
+
* @type {Date}
|
|
66
68
|
*/
|
|
67
|
-
input :
|
|
69
|
+
input : Date = null;
|
|
68
70
|
|
|
69
71
|
/**
|
|
70
72
|
* Current Date instance
|
|
@@ -195,7 +197,8 @@ export class PicoNow extends trait(PicoNowPlugins)
|
|
|
195
197
|
*/
|
|
196
198
|
valid() : boolean
|
|
197
199
|
{
|
|
198
|
-
|
|
200
|
+
// @ts-ignore
|
|
201
|
+
return !isNaN(this.input) && !isNaN(this.value);
|
|
199
202
|
}
|
|
200
203
|
|
|
201
204
|
/**
|
package/src/utils/Number.ts
CHANGED
|
@@ -148,7 +148,13 @@ export class PicoNumber
|
|
|
148
148
|
*/
|
|
149
149
|
static combine(value : number[]) : number
|
|
150
150
|
{
|
|
151
|
-
|
|
151
|
+
const iter = Arr.slice(...[
|
|
152
|
+
value, 1, value.length
|
|
153
|
+
]);
|
|
154
|
+
|
|
155
|
+
return Arr.reduce(iter, (acc : number, val : any) => {
|
|
156
|
+
return acc + val;
|
|
157
|
+
}, Arr.first(value) ?? 0);
|
|
152
158
|
}
|
|
153
159
|
|
|
154
160
|
/**
|
|
@@ -162,7 +168,13 @@ export class PicoNumber
|
|
|
162
168
|
*/
|
|
163
169
|
static subtract(value : number[]) : number
|
|
164
170
|
{
|
|
165
|
-
|
|
171
|
+
const iter = Arr.slice(...[
|
|
172
|
+
value, 1, value.length
|
|
173
|
+
]);
|
|
174
|
+
|
|
175
|
+
return Arr.reduce(iter, (acc : number, val : any) => {
|
|
176
|
+
return acc - val;
|
|
177
|
+
}, Arr.first(value) ?? 0);
|
|
166
178
|
}
|
|
167
179
|
|
|
168
180
|
/**
|
package/src/utils/Runner.ts
CHANGED
|
@@ -221,7 +221,7 @@ export class PicoRunner
|
|
|
221
221
|
*/
|
|
222
222
|
static framerate(cb : Function, fps : number = 30, finish : boolean = true) : Function
|
|
223
223
|
{
|
|
224
|
-
let timer : any, last = 0, hertz = 1000 / fps;
|
|
224
|
+
let timer : any, frame : any, last = 0, hertz = 1000 / fps;
|
|
225
225
|
|
|
226
226
|
const fn = (...args : any) => {
|
|
227
227
|
|
|
@@ -231,7 +231,13 @@ export class PicoRunner
|
|
|
231
231
|
return finish && (timer = setTimeout(fn, hertz + 1));
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
(
|
|
234
|
+
cancelAnimationFrame(frame);
|
|
235
|
+
|
|
236
|
+
frame = requestAnimationFrame(() => {
|
|
237
|
+
cb(...args);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
last = Date.now()
|
|
235
241
|
};
|
|
236
242
|
|
|
237
243
|
return fn;
|
package/src/utils/String.ts
CHANGED
package/types/index.esm.d.ts
CHANGED
|
@@ -17,6 +17,9 @@ export { go, browser, device, trait };
|
|
|
17
17
|
import { default as Data } from "./utils/Data.ts";
|
|
18
18
|
import { default as Route } from "./utils/Route.ts";
|
|
19
19
|
export { Route, Data };
|
|
20
|
+
import { default as Map } from "./wip/Map.ts";
|
|
21
|
+
import { default as Element } from "./wip/Element.ts";
|
|
22
|
+
export { Map, Element };
|
|
20
23
|
/**
|
|
21
24
|
* @type {Mix}
|
|
22
25
|
*/
|