@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,533 @@
|
|
|
1
|
+
import { Arr, Mix, Now, Num, Obj, Str } from "#src/index.esm.js";
|
|
2
|
+
|
|
3
|
+
export const NOW_MODIFY = {
|
|
4
|
+
'second': /([+-])([0-9]+)\s?seconds?/i,
|
|
5
|
+
'minute': /([+-])([0-9]+)\s?minutes?/i,
|
|
6
|
+
'hour': /([+-])([0-9]+)\s?hours?/i,
|
|
7
|
+
'date': /([+-])([0-9]+)\s?days?/i,
|
|
8
|
+
'month': /([+-])([0-9]+)\s?months?/i,
|
|
9
|
+
'year': /([+-])([0-9]+)\s?years?/i
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @memberof PicoNow
|
|
14
|
+
* @extends {PicoNow}
|
|
15
|
+
*/
|
|
16
|
+
export class PicoNowDefaultInstance
|
|
17
|
+
{
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get value by scope
|
|
21
|
+
*
|
|
22
|
+
* @example Now.get("year") // => 2026
|
|
23
|
+
*
|
|
24
|
+
* @param {string} scope Value scope
|
|
25
|
+
* @returns {number|PicoNow} Scope value
|
|
26
|
+
*/
|
|
27
|
+
get(scope)
|
|
28
|
+
{
|
|
29
|
+
if ( scope === 'time' ) {
|
|
30
|
+
return this.value.getTime();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if ( /^seconds?$/i.test(scope) ) {
|
|
34
|
+
return this.value.getSeconds();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if ( /^minutes?$/i.test(scope) ) {
|
|
38
|
+
return this.value.getMinutes();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if ( /^hours?$/i.test(scope) ) {
|
|
42
|
+
return this.value.getHours();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if ( /^days?$/i.test(scope) ) {
|
|
46
|
+
return this.value.getDay();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if ( /^dates?$/i.test(scope) ) {
|
|
50
|
+
return this.value.getDate();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if ( /^months?$/i.test(scope) ) {
|
|
54
|
+
return this.value.getMonth() + 1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if ( /^years?$/i.test(scope) ) {
|
|
58
|
+
return this.value.getFullYear();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Set value by scope
|
|
66
|
+
*
|
|
67
|
+
* @example Now.set(2026, "year")
|
|
68
|
+
*
|
|
69
|
+
* @param {any} value New value
|
|
70
|
+
* @param {string} scope Value scope
|
|
71
|
+
* @returns {PicoNow} Current instance
|
|
72
|
+
*/
|
|
73
|
+
set(value, scope)
|
|
74
|
+
{
|
|
75
|
+
if ( !Mix.isNum(value) ) {
|
|
76
|
+
value = Mix.int(value);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let day = this.value.getDay();
|
|
80
|
+
|
|
81
|
+
if ( scope === 'day' ) {
|
|
82
|
+
value = value + 1 - (day || 7);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if ( scope === 'time' ) {
|
|
86
|
+
this.value.setTime(value);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if ( /^seconds?$/i.test(scope) ) {
|
|
90
|
+
this.value.setSeconds(value);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if ( /^minutes?$/i.test(scope) ) {
|
|
94
|
+
this.value.setMinutes(value);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if ( /^hours?$/i.test(scope) ) {
|
|
98
|
+
this.value.setHours(value);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if ( /^days?$/i.test(scope) ) {
|
|
102
|
+
this.add(value, 'date');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if ( /^dates?$/i.test(scope) ) {
|
|
106
|
+
this.value.setDate(value);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if ( /^months?$/i.test(scope) ) {
|
|
110
|
+
this.value.setMonth(value - 1);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if ( /^years?$/i.test(scope) ) {
|
|
114
|
+
this.value.setFullYear(value);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Get or set timestamp
|
|
122
|
+
*
|
|
123
|
+
* @example Now.time() // => 1739334660000
|
|
124
|
+
*
|
|
125
|
+
* @param {any} [value] New timestamp
|
|
126
|
+
* @returns {number|PicoNow} Timestamp or instance
|
|
127
|
+
*/
|
|
128
|
+
time(value = null)
|
|
129
|
+
{
|
|
130
|
+
if ( value == null ) {
|
|
131
|
+
return this.get('time');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return this.set(value, 'time');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Get or set seconds
|
|
139
|
+
*
|
|
140
|
+
* @example Now.second() // => 45
|
|
141
|
+
*
|
|
142
|
+
* @param {any} [value] New seconds
|
|
143
|
+
* @returns {number|PicoNow} Seconds or instance
|
|
144
|
+
*/
|
|
145
|
+
second(value = null)
|
|
146
|
+
{
|
|
147
|
+
if ( value == null ) {
|
|
148
|
+
return this.get('second');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return this.set(value, 'second');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Get or set minutes
|
|
156
|
+
*
|
|
157
|
+
* @example Now.minute() // => 30
|
|
158
|
+
*
|
|
159
|
+
* @param {any} [value] New minutes
|
|
160
|
+
* @returns {number|PicoNow} Minutes or instance
|
|
161
|
+
*/
|
|
162
|
+
minute(value = null)
|
|
163
|
+
{
|
|
164
|
+
if ( value == null ) {
|
|
165
|
+
return this.get('minute');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return this.set(value, 'minute');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Get or set hours
|
|
173
|
+
*
|
|
174
|
+
* @example Now.hour() // => 12
|
|
175
|
+
*
|
|
176
|
+
* @param {any} [value] New hours
|
|
177
|
+
* @returns {number|PicoNow} Hours or instance
|
|
178
|
+
*/
|
|
179
|
+
hour(value = null)
|
|
180
|
+
{
|
|
181
|
+
if ( value == null ) {
|
|
182
|
+
return this.get('hour');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return this.set(value, 'hour');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Get or set day of week
|
|
190
|
+
*
|
|
191
|
+
* @example Now.day() // => 1
|
|
192
|
+
*
|
|
193
|
+
* @param {any} [value] New day
|
|
194
|
+
* @returns {number|PicoNow} Day or instance
|
|
195
|
+
*/
|
|
196
|
+
day(value = null)
|
|
197
|
+
{
|
|
198
|
+
if ( value == null ) {
|
|
199
|
+
return this.get('day');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return this.set(value, 'day');
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Get or set date of month
|
|
207
|
+
*
|
|
208
|
+
* @example Now.date() // => 12
|
|
209
|
+
*
|
|
210
|
+
* @param {any} [value] New date
|
|
211
|
+
* @returns {number|PicoNow} Date or instance
|
|
212
|
+
*/
|
|
213
|
+
date(value = null)
|
|
214
|
+
{
|
|
215
|
+
if ( value == null ) {
|
|
216
|
+
return this.get('date');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return this.set(value, 'date');
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Get or set month
|
|
224
|
+
*
|
|
225
|
+
* @example Now.month() // => 2
|
|
226
|
+
*
|
|
227
|
+
* @param {any} [value] New month
|
|
228
|
+
* @returns {number|PicoNow} Month or instance
|
|
229
|
+
*/
|
|
230
|
+
month(value = null)
|
|
231
|
+
{
|
|
232
|
+
if ( value == null ) {
|
|
233
|
+
return this.get('month');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return this.set(value, 'month');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Get or set year
|
|
241
|
+
*
|
|
242
|
+
* @example Now.year() // => 2026
|
|
243
|
+
*
|
|
244
|
+
* @param {any} [value] New year
|
|
245
|
+
* @returns {number|PicoNow} Year or instance
|
|
246
|
+
*/
|
|
247
|
+
year(value = null)
|
|
248
|
+
{
|
|
249
|
+
if ( value == null ) {
|
|
250
|
+
return this.get('year');
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return this.set(value, 'year');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Get short year
|
|
258
|
+
*
|
|
259
|
+
* @example Now.shortyear() // => "26"
|
|
260
|
+
*
|
|
261
|
+
* @returns {string} Short year
|
|
262
|
+
*/
|
|
263
|
+
shortyear()
|
|
264
|
+
{
|
|
265
|
+
return this.get('year').toString().slice(- 2);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Add value to scope
|
|
270
|
+
*
|
|
271
|
+
* @example Now.add(1, "day")
|
|
272
|
+
*
|
|
273
|
+
* @param {number} value Add value
|
|
274
|
+
* @param {string} [scope] Target scope
|
|
275
|
+
* @returns {PicoNow} Current instance
|
|
276
|
+
*/
|
|
277
|
+
add(value, scope = 'day')
|
|
278
|
+
{
|
|
279
|
+
if ( /^days?$/i.test(scope) ) {
|
|
280
|
+
scope = 'date';
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
this.set(this.get(scope) + Mix.int(value), scope);
|
|
284
|
+
|
|
285
|
+
return this;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Subtract value from scope
|
|
290
|
+
*
|
|
291
|
+
* @example Now.sub(1, "day")
|
|
292
|
+
*
|
|
293
|
+
* @param {number} value Sub value
|
|
294
|
+
* @param {string} [scope] Target scope
|
|
295
|
+
* @returns {PicoNow} Current instance
|
|
296
|
+
*/
|
|
297
|
+
sub(value, scope = 'day')
|
|
298
|
+
{
|
|
299
|
+
if ( /^days?$/i.test(scope) ) {
|
|
300
|
+
scope = 'date';
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
this.set(this.get(scope) - Mix.int(value), scope);
|
|
304
|
+
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Check if string is modifiable
|
|
310
|
+
*
|
|
311
|
+
* @example Now.isModifible("+1 day") // => true
|
|
312
|
+
*
|
|
313
|
+
* @param {string} value Test value
|
|
314
|
+
* @returns {boolean} Is modifiable
|
|
315
|
+
*/
|
|
316
|
+
isModifible(value)
|
|
317
|
+
{
|
|
318
|
+
return /^(\s*[+-][0-9]+\s?[a-z]+\s*)+$/i.test(value);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Modify date by string
|
|
323
|
+
*
|
|
324
|
+
* @example Now.modify("+1 day")
|
|
325
|
+
*
|
|
326
|
+
* @param {string} value Modify string
|
|
327
|
+
* @returns {PicoNow} Current instance
|
|
328
|
+
*/
|
|
329
|
+
modify(value)
|
|
330
|
+
{
|
|
331
|
+
if ( Mix.isEmpty(value) ) {
|
|
332
|
+
return this;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
Obj.each(NOW_MODIFY, (val, key) => {
|
|
336
|
+
Str.match(value, val, ([f, o, c]) => {
|
|
337
|
+
o === '+' ? this.add(c, key) : this.sub(c, key);
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
return this;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Apply values from other date
|
|
346
|
+
*
|
|
347
|
+
* @example Now.apply("2026-01-01", "YYYY-MM-DD", ["year"])
|
|
348
|
+
*
|
|
349
|
+
* @param {any} value Source value
|
|
350
|
+
* @param {string} [format] Source format
|
|
351
|
+
* @param {Array<string>} [keys] Scope keys
|
|
352
|
+
* @returns {PicoNow} Current instance
|
|
353
|
+
*/
|
|
354
|
+
apply(value, format = 'YYYY-MM-DD HH:mm:ss', keys = [])
|
|
355
|
+
{
|
|
356
|
+
value = Now.make(value, format);
|
|
357
|
+
|
|
358
|
+
for ( const key of keys ) {
|
|
359
|
+
this.set(value.get(key), key);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return this;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Apply date from other value
|
|
367
|
+
*
|
|
368
|
+
* @example Now.applyDate("2026-01-01")
|
|
369
|
+
*
|
|
370
|
+
* @param {any} value Source value
|
|
371
|
+
* @param {string} [format] Source format
|
|
372
|
+
* @returns {PicoNow} Current instance
|
|
373
|
+
*/
|
|
374
|
+
applyDate(value, format = 'YYYY-MM-DD HH:mm:ss')
|
|
375
|
+
{
|
|
376
|
+
return this.apply(value, format, ['date', 'month', 'year']);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Apply time from other value
|
|
381
|
+
*
|
|
382
|
+
* @example Now.applyTime("12:00:00")
|
|
383
|
+
*
|
|
384
|
+
* @param {any} value Source value
|
|
385
|
+
* @param {string} [format] Source format
|
|
386
|
+
* @returns {PicoNow} Current instance
|
|
387
|
+
*/
|
|
388
|
+
applyTime(value, format = 'YYYY-MM-DD HH:mm:ss')
|
|
389
|
+
{
|
|
390
|
+
return this.apply(value, format, ['hour', 'minute', 'second']);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* @see PicoNow.add
|
|
397
|
+
*/
|
|
398
|
+
PicoNowGridInstance.prototype.addSecond = function (value) {
|
|
399
|
+
console.warn('Now.addSecond() is deprecated, use Now.add(value, \'second\') instead.');
|
|
400
|
+
return this.add(value, 'second');
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* @see PicoNow.sub
|
|
405
|
+
*/
|
|
406
|
+
PicoNowGridInstance.prototype.subSecond = function (value) {
|
|
407
|
+
console.warn('Now.subSecond() is deprecated, use Now.sub(value, \'second\') instead.');
|
|
408
|
+
return this.sub(value, 'second');
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* @see PicoNow.add
|
|
413
|
+
*/
|
|
414
|
+
PicoNowGridInstance.prototype.addMinute = function (value) {
|
|
415
|
+
console.warn('Now.addMinute() is deprecated, use Now.add(value, \'minute\') instead.');
|
|
416
|
+
return this.add(value, 'minute');
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* @see PicoNow.sub
|
|
421
|
+
*/
|
|
422
|
+
PicoNowGridInstance.prototype.subMinute = function (value) {
|
|
423
|
+
console.warn('Now.subMinute() is deprecated, use Now.sub(value, \'minute\') instead.');
|
|
424
|
+
return this.sub(value, 'minute');
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* @see PicoNow.add
|
|
429
|
+
*/
|
|
430
|
+
PicoNowGridInstance.prototype.addHour = function (value) {
|
|
431
|
+
console.warn('Now.addHour() is deprecated, use Now.add(value, \'hour\') instead.');
|
|
432
|
+
return this.add(value, 'hour');
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* @see PicoNow.sub
|
|
437
|
+
*/
|
|
438
|
+
PicoNowGridInstance.prototype.subHour = function (value) {
|
|
439
|
+
console.warn('Now.subHour() is deprecated, use Now.sub(value, \'hour\') instead.');
|
|
440
|
+
return this.sub(value, 'hour');
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* @see PicoNow.add
|
|
445
|
+
*/
|
|
446
|
+
PicoNowGridInstance.prototype.addDates = function (value) {
|
|
447
|
+
console.warn('Now.addDates() is deprecated, use Now.add(value, \'date\') instead.');
|
|
448
|
+
return this.add(value, 'date');
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* @see PicoNow.sub
|
|
453
|
+
*/
|
|
454
|
+
PicoNowGridInstance.prototype.subDates = function (value) {
|
|
455
|
+
console.warn('Now.subDates() is deprecated, use Now.sub(value, \'date\') instead.');
|
|
456
|
+
return this.sub(value, 'date');
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* @see PicoNow.add
|
|
461
|
+
*/
|
|
462
|
+
PicoNowGridInstance.prototype.addMonths = function (value) {
|
|
463
|
+
console.warn('Now.addMonths() is deprecated, use Now.add(value, \'month\') instead.');
|
|
464
|
+
return this.add(value, 'month');
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* @see PicoNow.sub
|
|
469
|
+
*/
|
|
470
|
+
PicoNowGridInstance.prototype.subMonths = function (value) {
|
|
471
|
+
console.warn('Now.subMonths() is deprecated, use Now.sub(value, \'month\') instead.');
|
|
472
|
+
return this.sub(value, 'month');
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* @see PicoNow.add
|
|
477
|
+
*/
|
|
478
|
+
PicoNowGridInstance.prototype.addYears = function (value) {
|
|
479
|
+
console.warn('Now.addYears() is deprecated, use Now.add(value, \'year\') instead.');
|
|
480
|
+
return this.add(value, 'year');
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* @see PicoNow.sub
|
|
485
|
+
*/
|
|
486
|
+
PicoNowGridInstance.prototype.subYears = function (value) {
|
|
487
|
+
console.warn('Now.subYears() is deprecated, use Now.sub(value, \'year\') instead.');
|
|
488
|
+
return this.sub(value, 'year');
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* @see PicoNow.add
|
|
493
|
+
*/
|
|
494
|
+
PicoNowGridInstance.prototype.addDecades = function (value) {
|
|
495
|
+
console.warn('Now.addDecades() is deprecated, use Now.grid(10 * value, \'year\') instead.');
|
|
496
|
+
return this.add(10 * value, 'year');
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* @see PicoNow.sub
|
|
501
|
+
*/
|
|
502
|
+
PicoNowGridInstance.prototype.subDecades = function (value) {
|
|
503
|
+
console.warn('Now.subDecades() is deprecated, use Now.grid(10 * value, \'year\') instead.');
|
|
504
|
+
return this.sub(10 * value, 'year');
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* @see PicoNow.day
|
|
509
|
+
*/
|
|
510
|
+
PicoNowGridInstance.prototype.humanDay = function () {
|
|
511
|
+
console.warn('Now.humanDay() is deprecated, use Now.day() instead.');
|
|
512
|
+
return this.day();
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* @see PicoNow.month
|
|
517
|
+
*/
|
|
518
|
+
PicoNowGridInstance.prototype.humanMonth = function () {
|
|
519
|
+
console.warn('Now.humanMonth() is deprecated, use Now.month() instead.');
|
|
520
|
+
return this.month();
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* @returns {typeof import('#src/utils/Now.js').PicoNow}
|
|
525
|
+
*/
|
|
526
|
+
export const PicoNowDefaultPlugin = function (self) {
|
|
527
|
+
|
|
528
|
+
Obj.each(Mix.proto(PicoNowDefaultInstance), (fn, id) => {
|
|
529
|
+
self.prototype[id] = fn;
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
return self;
|
|
533
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { Arr, Locale, Mix, Num, Obj, Str } from "#src/index.esm.js";
|
|
2
|
+
|
|
3
|
+
export const NOW_FORMAT = {
|
|
4
|
+
'L': 'DD/MM/YYYY',
|
|
5
|
+
'LL': 'MMMM DD, YYYY',
|
|
6
|
+
'LLL': 'MMMM DD, YYYY HH:mm',
|
|
7
|
+
'LLLL': 'dddd, MMMM DD, YYYY HH:mm'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const NOW_PARSE = {
|
|
11
|
+
'second': 'ss',
|
|
12
|
+
'minute': 'mm',
|
|
13
|
+
'hour': 'HH',
|
|
14
|
+
'date': 'DD',
|
|
15
|
+
'month': 'MM',
|
|
16
|
+
'year': 'YYYY'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @memberof PicoNow
|
|
21
|
+
* @extends {PicoNow}
|
|
22
|
+
*/
|
|
23
|
+
export class PicoNowFormatInstance
|
|
24
|
+
{
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check if value matches format
|
|
28
|
+
*
|
|
29
|
+
* @example Now.isParsable("2026-01-01") // => true
|
|
30
|
+
*
|
|
31
|
+
* @param {string} value Test value
|
|
32
|
+
* @param {string} [format] Date format
|
|
33
|
+
* @returns {boolean} Is parsable
|
|
34
|
+
*/
|
|
35
|
+
isParsable(value, format = 'YYYY-MM-DD HH:mm:ss')
|
|
36
|
+
{
|
|
37
|
+
for ( const key in NOW_PARSE ) {
|
|
38
|
+
value = Str.replace(value, NOW_PARSE[key], format);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return value === format;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Parse date from string
|
|
46
|
+
*
|
|
47
|
+
* @example Now.parse("2026-01-01") // => Now
|
|
48
|
+
*
|
|
49
|
+
* @param {any} value Input value
|
|
50
|
+
* @param {string} [format] Input format
|
|
51
|
+
* @returns {PicoNow} Current instance
|
|
52
|
+
*/
|
|
53
|
+
parse(value, format = 'YYYY-MM-DD HH:mm:ss')
|
|
54
|
+
{
|
|
55
|
+
if ( Mix.isTime(value) ) {
|
|
56
|
+
format = 'HH:mm:ss';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if ( Mix.isDate(value) ) {
|
|
60
|
+
format = 'YYYY-MM-DD';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if ( this.isModifible(value) ) {
|
|
64
|
+
return this.modify(value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if ( ! Mix.isIsoDate(value) ) {
|
|
68
|
+
return this.parseFormat(value, format);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this.value = new Date(value);
|
|
72
|
+
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Parse date using format
|
|
78
|
+
*
|
|
79
|
+
* @example Now.parseFormat("01/01/2026", "DD/MM/YYYY")
|
|
80
|
+
*
|
|
81
|
+
* @param {string} value Input value
|
|
82
|
+
* @param {string} format Input format
|
|
83
|
+
* @returns {PicoNow} Current instance
|
|
84
|
+
*/
|
|
85
|
+
parseFormat(value, format)
|
|
86
|
+
{
|
|
87
|
+
if ( !this.isParsable(value, format) ) {
|
|
88
|
+
return (this.value = new Date(NaN), this);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for ( const key in NOW_PARSE ) {
|
|
92
|
+
this.set(Str.extract(value, NOW_PARSE[key], format), key);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Format date to string
|
|
100
|
+
*
|
|
101
|
+
* @example Now.format("YYYY-MM-DD") // => "2026-02-12"
|
|
102
|
+
*
|
|
103
|
+
* @param {string} [format] Output format
|
|
104
|
+
* @returns {string} Formatted string
|
|
105
|
+
*/
|
|
106
|
+
format(format = 'YYYY-MM-DD HH:mm:ss')
|
|
107
|
+
{
|
|
108
|
+
if ( Obj.has(NOW_FORMAT, format) ) {
|
|
109
|
+
format = Locale.trans(NOW_FORMAT[format]);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
format = format.replace('dddd', () => {
|
|
113
|
+
return this.human('day');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
format = format.replace('ddd', () => {
|
|
117
|
+
return this.human('day', 3);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
format = format.replace('dd', () => {
|
|
121
|
+
return this.human('day', 2);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
format = format.replace('MMMM', () => {
|
|
125
|
+
return this.human('month');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
format = format.replace('MMM', () => {
|
|
129
|
+
return this.human('month', 3);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
format = format.replace('YYYY', () => {
|
|
133
|
+
return Str.integer(this.year(), 4);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
format = format.replace('MM', () => {
|
|
137
|
+
return Str.integer(this.month(), 2);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
format = format.replace('DD', () => {
|
|
141
|
+
return Str.integer(this.date(), 2);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
format = format.replace('HH', () => {
|
|
145
|
+
return Str.integer(this.hour(), 2);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
format = format.replace('mm', () => {
|
|
149
|
+
return Str.integer(this.minute(), 2);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
format = format.replace('ss', () => {
|
|
153
|
+
return Str.integer(this.second(), 2);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
format = format.replace('YY', () => {
|
|
157
|
+
return Str.integer(this.shortyear(), 2);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
format = format.replace('X', () => {
|
|
161
|
+
return Str.integer(this.time());
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
format = format.replace('x', () => {
|
|
165
|
+
return Str.integer(this.time() / 1000);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return format;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Format date as integer
|
|
173
|
+
*
|
|
174
|
+
* @example Now.code("YYYYMMDD") // => 20260212
|
|
175
|
+
*
|
|
176
|
+
* @param {string} [format] Output format
|
|
177
|
+
* @returns {number} Formatted integer
|
|
178
|
+
*/
|
|
179
|
+
code(format = 'X')
|
|
180
|
+
{
|
|
181
|
+
return Mix.int(this.format(format));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @returns {typeof import('#src/utils/Now.js').PicoNow}
|
|
188
|
+
*/
|
|
189
|
+
export const PicoNowFormatPlugin = function (self) {
|
|
190
|
+
|
|
191
|
+
Obj.each(Mix.proto(PicoNowFormatInstance), (fn, id) => {
|
|
192
|
+
self.prototype[id] = fn;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return self;
|
|
196
|
+
}
|