@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,544 @@
|
|
|
1
|
+
import { Mix, Now, Obj } from "#src/index.esm.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @memberof PicoNow
|
|
5
|
+
* @extends {PicoNow}
|
|
6
|
+
*/
|
|
7
|
+
export class PicoNowWalkerInstance
|
|
8
|
+
{
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get previous date by scope
|
|
12
|
+
*
|
|
13
|
+
* @example Now.prev("day") // => Now
|
|
14
|
+
*
|
|
15
|
+
* @param {string} [scope] Target scope
|
|
16
|
+
* @returns {PicoNow} New instance
|
|
17
|
+
*/
|
|
18
|
+
prev(scope = 'date')
|
|
19
|
+
{
|
|
20
|
+
if ( /^days?$/i.test(scope) ) {
|
|
21
|
+
scope = 'date';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if ( /^decades?$/i.test(scope) ) {
|
|
25
|
+
return this.clone().sub(10, 'year');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return this.clone().sub(1, scope);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get next date by scope
|
|
33
|
+
*
|
|
34
|
+
* @example Now.next("day") // => Now
|
|
35
|
+
*
|
|
36
|
+
* @param {string} [scope] Target scope
|
|
37
|
+
* @returns {PicoNow} New instance
|
|
38
|
+
*/
|
|
39
|
+
next(scope = 'day')
|
|
40
|
+
{
|
|
41
|
+
if ( /^days?$/i.test(scope) ) {
|
|
42
|
+
scope = 'date';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if ( /^decades?$/i.test(scope) ) {
|
|
46
|
+
return this.clone().add(10, 'year');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return this.clone().add(1, scope);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get previous second
|
|
54
|
+
*
|
|
55
|
+
* @example Now.prevSecond()
|
|
56
|
+
*
|
|
57
|
+
* @returns {PicoNow} New instance
|
|
58
|
+
*/
|
|
59
|
+
prevSecond()
|
|
60
|
+
{
|
|
61
|
+
return this.prev('second');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Get next second
|
|
66
|
+
*
|
|
67
|
+
* @example Now.nextSecond()
|
|
68
|
+
*
|
|
69
|
+
* @returns {PicoNow} New instance
|
|
70
|
+
*/
|
|
71
|
+
nextSecond()
|
|
72
|
+
{
|
|
73
|
+
return this.next('second');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get previous minute
|
|
78
|
+
*
|
|
79
|
+
* @example Now.prevMinute()
|
|
80
|
+
*
|
|
81
|
+
* @returns {PicoNow} New instance
|
|
82
|
+
*/
|
|
83
|
+
prevMinute()
|
|
84
|
+
{
|
|
85
|
+
return this.prev('minute');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Get next minute
|
|
90
|
+
*
|
|
91
|
+
* @example Now.nextMinute()
|
|
92
|
+
*
|
|
93
|
+
* @returns {PicoNow} New instance
|
|
94
|
+
*/
|
|
95
|
+
nextMinute()
|
|
96
|
+
{
|
|
97
|
+
return this.next('minute');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Get previous hour
|
|
102
|
+
*
|
|
103
|
+
* @example Now.prevHour()
|
|
104
|
+
*
|
|
105
|
+
* @returns {PicoNow} New instance
|
|
106
|
+
*/
|
|
107
|
+
prevHour()
|
|
108
|
+
{
|
|
109
|
+
return this.prev('hour');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Get next hour
|
|
114
|
+
*
|
|
115
|
+
* @example Now.nextHour()
|
|
116
|
+
*
|
|
117
|
+
* @returns {PicoNow} New instance
|
|
118
|
+
*/
|
|
119
|
+
nextHour()
|
|
120
|
+
{
|
|
121
|
+
return this.next('hour');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Get previous date
|
|
126
|
+
*
|
|
127
|
+
* @example Now.prevDate()
|
|
128
|
+
*
|
|
129
|
+
* @returns {PicoNow} New instance
|
|
130
|
+
*/
|
|
131
|
+
prevDate()
|
|
132
|
+
{
|
|
133
|
+
return this.prev('date');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Get next date
|
|
138
|
+
*
|
|
139
|
+
* @example Now.nextDate()
|
|
140
|
+
*
|
|
141
|
+
* @returns {PicoNow} New instance
|
|
142
|
+
*/
|
|
143
|
+
nextDate()
|
|
144
|
+
{
|
|
145
|
+
return this.next('date');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get previous month
|
|
150
|
+
*
|
|
151
|
+
* @example Now.prevMonth()
|
|
152
|
+
*
|
|
153
|
+
* @returns {PicoNow} New instance
|
|
154
|
+
*/
|
|
155
|
+
prevMonth()
|
|
156
|
+
{
|
|
157
|
+
return this.prev('month');
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Get next month
|
|
162
|
+
*
|
|
163
|
+
* @example Now.nextMonth()
|
|
164
|
+
*
|
|
165
|
+
* @returns {PicoNow} New instance
|
|
166
|
+
*/
|
|
167
|
+
nextMonth()
|
|
168
|
+
{
|
|
169
|
+
return this.next('month');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Get previous year
|
|
174
|
+
*
|
|
175
|
+
* @example Now.prevYear()
|
|
176
|
+
*
|
|
177
|
+
* @returns {PicoNow} New instance
|
|
178
|
+
*/
|
|
179
|
+
prevYear()
|
|
180
|
+
{
|
|
181
|
+
return this.prev('year');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get next year
|
|
186
|
+
*
|
|
187
|
+
* @example Now.nextYear()
|
|
188
|
+
*
|
|
189
|
+
* @returns {PicoNow} New instance
|
|
190
|
+
*/
|
|
191
|
+
nextYear()
|
|
192
|
+
{
|
|
193
|
+
return this.next('year');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Get previous decade
|
|
198
|
+
*
|
|
199
|
+
* @example Now.prevDecade()
|
|
200
|
+
*
|
|
201
|
+
* @returns {PicoNow} New instance
|
|
202
|
+
*/
|
|
203
|
+
prevDecade()
|
|
204
|
+
{
|
|
205
|
+
return this.prev('decade');
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Get next decade
|
|
210
|
+
*
|
|
211
|
+
* @example Now.nextDecade()
|
|
212
|
+
*
|
|
213
|
+
* @returns {PicoNow} New instance
|
|
214
|
+
*/
|
|
215
|
+
nextDecade()
|
|
216
|
+
{
|
|
217
|
+
return this.next('decade');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Get start of scope
|
|
222
|
+
*
|
|
223
|
+
* @example Now.first("month")
|
|
224
|
+
*
|
|
225
|
+
* @param {string} [scope] Target scope
|
|
226
|
+
* @returns {PicoNow} New instance
|
|
227
|
+
*/
|
|
228
|
+
first(scope = 'date')
|
|
229
|
+
{
|
|
230
|
+
if ( /^seconds?$/i.test(scope) ) {
|
|
231
|
+
return this.firstSecond();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if ( /^minutes?$/i.test(scope) ) {
|
|
235
|
+
return this.firstMinute();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if ( /^hours?$/i.test(scope) ) {
|
|
239
|
+
return this.firstHour();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if ( /^days?$/i.test(scope) ) {
|
|
243
|
+
return this.firstDay();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if ( /^dates?$/i.test(scope) ) {
|
|
247
|
+
return this.firstDate();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if ( /^months?$/i.test(scope) ) {
|
|
251
|
+
return this.firstMonth();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if ( /^years?$/i.test(scope) ) {
|
|
255
|
+
return this.firstYear();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if ( /^decades?$/i.test(scope) ) {
|
|
259
|
+
return this.firstDecade();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
throw new Error(`Invalid first scope type "${scope}".`);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Get end of scope
|
|
267
|
+
*
|
|
268
|
+
* @example Now.last("month")
|
|
269
|
+
*
|
|
270
|
+
* @param {string} [scope] Target scope
|
|
271
|
+
* @returns {PicoNow} New instance
|
|
272
|
+
*/
|
|
273
|
+
last(scope = 'date')
|
|
274
|
+
{
|
|
275
|
+
if ( /^seconds?$/i.test(scope) ) {
|
|
276
|
+
return this.lastSecond();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if ( /^minutes?$/i.test(scope) ) {
|
|
280
|
+
return this.lastMinute();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if ( /^hours?$/i.test(scope) ) {
|
|
284
|
+
return this.lastHour();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if ( /^days?$/i.test(scope) ) {
|
|
288
|
+
return this.lastDay();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if ( /^dates?$/i.test(scope) ) {
|
|
292
|
+
return this.lastDate();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if ( /^months?$/i.test(scope) ) {
|
|
296
|
+
return this.lastMonth();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if ( /^years?$/i.test(scope) ) {
|
|
300
|
+
return this.lastYear();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if ( /^decades?$/i.test(scope) ) {
|
|
304
|
+
return this.lastDecade();
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
throw new Error(`Invalid last scope type "${scope}".`);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Get start of second
|
|
312
|
+
*
|
|
313
|
+
* @example Now.firstSecond()
|
|
314
|
+
*
|
|
315
|
+
* @returns {PicoNow} New instance
|
|
316
|
+
*/
|
|
317
|
+
firstSecond()
|
|
318
|
+
{
|
|
319
|
+
return this.clone().set(0, 'second');
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Get end of second
|
|
324
|
+
*
|
|
325
|
+
* @example Now.lastSecond()
|
|
326
|
+
*
|
|
327
|
+
* @returns {PicoNow} New instance
|
|
328
|
+
*/
|
|
329
|
+
lastSecond()
|
|
330
|
+
{
|
|
331
|
+
return this.clone().set(59, 'second');
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Get start of minute
|
|
336
|
+
*
|
|
337
|
+
* @example Now.firstMinute()
|
|
338
|
+
*
|
|
339
|
+
* @returns {PicoNow} New instance
|
|
340
|
+
*/
|
|
341
|
+
firstMinute()
|
|
342
|
+
{
|
|
343
|
+
return this.clone().set(0, 'minute');
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Get end of minute
|
|
348
|
+
*
|
|
349
|
+
* @example Now.lastMinute()
|
|
350
|
+
*
|
|
351
|
+
* @returns {PicoNow} New instance
|
|
352
|
+
*/
|
|
353
|
+
lastMinute()
|
|
354
|
+
{
|
|
355
|
+
return this.clone().set(59, 'minute');
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Get start of hour
|
|
360
|
+
*
|
|
361
|
+
* @example Now.firstHour()
|
|
362
|
+
*
|
|
363
|
+
* @returns {PicoNow} New instance
|
|
364
|
+
*/
|
|
365
|
+
firstHour()
|
|
366
|
+
{
|
|
367
|
+
return this.clone().set(0, 'hour');
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Get end of hour
|
|
372
|
+
*
|
|
373
|
+
* @example Now.lastHour()
|
|
374
|
+
*
|
|
375
|
+
* @returns {PicoNow} New instance
|
|
376
|
+
*/
|
|
377
|
+
lastHour()
|
|
378
|
+
{
|
|
379
|
+
return this.clone().set(23, 'hour');
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Get start of day
|
|
384
|
+
*
|
|
385
|
+
* @example Now.firstDay()
|
|
386
|
+
*
|
|
387
|
+
* @returns {PicoNow} New instance
|
|
388
|
+
*/
|
|
389
|
+
firstDay()
|
|
390
|
+
{
|
|
391
|
+
return this.clone().set(0, 'day');
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Get end of day
|
|
396
|
+
*
|
|
397
|
+
* @example Now.lastDay()
|
|
398
|
+
*
|
|
399
|
+
* @returns {PicoNow} New instance
|
|
400
|
+
*/
|
|
401
|
+
lastDay()
|
|
402
|
+
{
|
|
403
|
+
return this.clone().set(6, 'day');
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Get start of month date
|
|
408
|
+
*
|
|
409
|
+
* @example Now.firstDate()
|
|
410
|
+
*
|
|
411
|
+
* @returns {PicoNow} New instance
|
|
412
|
+
*/
|
|
413
|
+
firstDate()
|
|
414
|
+
{
|
|
415
|
+
return this.clone().set(1, 'date');
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Get end of month date
|
|
420
|
+
*
|
|
421
|
+
* @example Now.lastDate()
|
|
422
|
+
*
|
|
423
|
+
* @returns {PicoNow} New instance
|
|
424
|
+
*/
|
|
425
|
+
lastDate()
|
|
426
|
+
{
|
|
427
|
+
return this.clone().next('month').set(0, 'date');
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Get start of year month
|
|
432
|
+
*
|
|
433
|
+
* @example Now.firstMonth()
|
|
434
|
+
*
|
|
435
|
+
* @returns {PicoNow} New instance
|
|
436
|
+
*/
|
|
437
|
+
firstMonth()
|
|
438
|
+
{
|
|
439
|
+
return this.clone().set(1, 'month');
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Get end of year month
|
|
444
|
+
*
|
|
445
|
+
* @example Now.lastMonth()
|
|
446
|
+
*
|
|
447
|
+
* @returns {PicoNow} New instance
|
|
448
|
+
*/
|
|
449
|
+
lastMonth()
|
|
450
|
+
{
|
|
451
|
+
return this.clone().set(12, 'month');
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Get nth year of decade
|
|
456
|
+
*
|
|
457
|
+
* @example Now.nthYear(5)
|
|
458
|
+
*
|
|
459
|
+
* @param {number} [n] Year index
|
|
460
|
+
* @returns {PicoNow} New instance
|
|
461
|
+
*/
|
|
462
|
+
nthYear(n = 0)
|
|
463
|
+
{
|
|
464
|
+
let year = Math.floor(this.year() / 10) * 10;
|
|
465
|
+
|
|
466
|
+
return this.clone().set(year + n, 'year');
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Get first year of decade
|
|
471
|
+
*
|
|
472
|
+
* @example Now.firstYear()
|
|
473
|
+
*
|
|
474
|
+
* @returns {PicoNow} New instance
|
|
475
|
+
*/
|
|
476
|
+
firstYear()
|
|
477
|
+
{
|
|
478
|
+
return this.nthYear(0);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Get last year of decade
|
|
483
|
+
*
|
|
484
|
+
* @example Now.lastYear()
|
|
485
|
+
*
|
|
486
|
+
* @returns {PicoNow} New instance
|
|
487
|
+
*/
|
|
488
|
+
lastYear()
|
|
489
|
+
{
|
|
490
|
+
return this.nthYear(9);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Get nth decade of century
|
|
495
|
+
*
|
|
496
|
+
* @example Now.nthDecade(5)
|
|
497
|
+
*
|
|
498
|
+
* @param {number} [n] Decade index
|
|
499
|
+
* @returns {PicoNow} New instance
|
|
500
|
+
*/
|
|
501
|
+
nthDecade(n = 0)
|
|
502
|
+
{
|
|
503
|
+
let year = Math.floor(this.year() / 100) * 100;
|
|
504
|
+
|
|
505
|
+
return this.clone().set(year + (n * 10), 'year');
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Get first decade of century
|
|
510
|
+
*
|
|
511
|
+
* @example Now.firstDecade()
|
|
512
|
+
*
|
|
513
|
+
* @returns {PicoNow} New instance
|
|
514
|
+
*/
|
|
515
|
+
firstDecade()
|
|
516
|
+
{
|
|
517
|
+
return this.nthDecade(0);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* Get last decade of century
|
|
522
|
+
*
|
|
523
|
+
* @example Now.lastDecade()
|
|
524
|
+
*
|
|
525
|
+
* @returns {PicoNow} New instance
|
|
526
|
+
*/
|
|
527
|
+
lastDecade()
|
|
528
|
+
{
|
|
529
|
+
return this.nthDecade(9);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* @returns {typeof import('#src/utils/Now.js').PicoNow}
|
|
536
|
+
*/
|
|
537
|
+
export const PicoNowWalkerPlugin = function (self) {
|
|
538
|
+
|
|
539
|
+
Obj.each(Mix.proto(PicoNowWalkerInstance), (fn, id) => {
|
|
540
|
+
self.prototype[id] = fn;
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
return self;
|
|
544
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get global runtime scope
|
|
3
|
+
*
|
|
4
|
+
* @example go().Math // => Math
|
|
5
|
+
*
|
|
6
|
+
* @returns {any} Global scope obj
|
|
7
|
+
*/
|
|
8
|
+
export function go() {
|
|
9
|
+
|
|
10
|
+
if ( typeof globalThis !== 'undefined' ) {
|
|
11
|
+
return globalThis;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if ( typeof window !== 'undefined' ) {
|
|
15
|
+
return window;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if ( typeof global !== 'undefined' ) {
|
|
19
|
+
return global;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Detect browser from userAgent
|
|
27
|
+
*
|
|
28
|
+
* @example browser() // sets global flags
|
|
29
|
+
*
|
|
30
|
+
* @returns {void} No return value
|
|
31
|
+
*/
|
|
32
|
+
export function browser() {
|
|
33
|
+
|
|
34
|
+
const scope = go();
|
|
35
|
+
|
|
36
|
+
if ( ! scope.navigator ) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let [agent, result] = [
|
|
41
|
+
scope.navigator.userAgent, {}
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
if ( result.safari == null ) {
|
|
45
|
+
result.safari = /Safari\//.test(agent);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if ( result.firefox == null ) {
|
|
49
|
+
result.firefox = /Firefox\//.test(agent);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if ( result.edge == null ) {
|
|
53
|
+
result.edge = /Edge\//.test(agent);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if ( result.chrome == null ) {
|
|
57
|
+
result.chrome = /Chrome\//.test(agent);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
scope.piuag = result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Detect device OS from userAgent
|
|
65
|
+
*
|
|
66
|
+
* @example device() // sets global flags
|
|
67
|
+
*
|
|
68
|
+
* @returns {void} No return value
|
|
69
|
+
*/
|
|
70
|
+
export function device() {
|
|
71
|
+
|
|
72
|
+
const scope = go();
|
|
73
|
+
|
|
74
|
+
if ( ! scope.navigator ) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let [agent, result] = [
|
|
79
|
+
scope.navigator.userAgent, {}
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
if ( result.win == null ) {
|
|
83
|
+
result.win = /Windows/.test(agent);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if ( result.osx == null ) {
|
|
87
|
+
result.osx = /Macintosh|Mac OS X/.test(agent);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if ( result.gnu == null ) {
|
|
91
|
+
result.gnu = /Linux/.test(agent);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if ( result.ios == null ) {
|
|
95
|
+
result.ios = /iPhone|iPad|iPod/.test(agent);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if ( result.oid == null ) {
|
|
99
|
+
result.oid = /Android/.test(agent);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
scope.piudv = result;
|
|
103
|
+
}
|