@kizmann/pico-js 1.0.14 → 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
package/src/utility/now.js
DELETED
|
@@ -1,544 +0,0 @@
|
|
|
1
|
-
import { Num, Arr, Any } from "../index.js";
|
|
2
|
-
|
|
3
|
-
export class Now
|
|
4
|
-
{
|
|
5
|
-
initialDate = null;
|
|
6
|
-
moment = null;
|
|
7
|
-
|
|
8
|
-
constructor(date = null, format = 'YYYY-MM-DD HH:mm:ss')
|
|
9
|
-
{
|
|
10
|
-
let win = Any.global();
|
|
11
|
-
|
|
12
|
-
if ( ! win.moment ) {
|
|
13
|
-
throw new Error('Moment.js is required for pi.Now');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if ( date instanceof Now ) {
|
|
17
|
-
date = date.get().toDate();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
this.initialDate = date;
|
|
21
|
-
|
|
22
|
-
if ( ! Any.isString(date) ) {
|
|
23
|
-
this.moment = win.moment(date || new Date, format);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if ( this.moment !== null ) {
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
this.moment = win.moment(date.match(/^now/) ?
|
|
31
|
-
new Date : date, format);
|
|
32
|
-
|
|
33
|
-
let second = this.initialDate.match(/(\+|-)([0-9]+)seconds?/);
|
|
34
|
-
|
|
35
|
-
if ( Any.isEmpty(second) === false && second[1] === '+' ) {
|
|
36
|
-
this.moment.add(second[2], 'second');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
let minute = this.initialDate.match(/(\+|-)([0-9]+)minutes?/);
|
|
40
|
-
|
|
41
|
-
if ( Any.isEmpty(minute) === false && minute[1] === '+' ) {
|
|
42
|
-
this.moment.add(minute[2], 'minute');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
let hour = this.initialDate.match(/(\+|-)([0-9]+)hours?/);
|
|
46
|
-
|
|
47
|
-
if ( Any.isEmpty(hour) === false && hour[1] === '+' ) {
|
|
48
|
-
this.moment.add(hour[2], 'hour');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let day = this.initialDate.match(/(\+|-)([0-9]+)days?/);
|
|
52
|
-
|
|
53
|
-
if ( Any.isEmpty(day) === false && day[1] === '+' ) {
|
|
54
|
-
this.moment.add(day[2], 'day');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if ( Any.isEmpty(day) === false && day[1] === '-' ) {
|
|
58
|
-
this.moment.subtract(day[2], 'day');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
let month = this.initialDate.match(/(\+|-)([0-9]+)months?/);
|
|
62
|
-
|
|
63
|
-
if ( Any.isEmpty(month) === false && month[1] === '+' ) {
|
|
64
|
-
this.moment.add(month[2], 'month');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if ( Any.isEmpty(month) === false && month[1] === '-' ) {
|
|
68
|
-
this.moment.subtract(month[2], 'month');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
let year = this.initialDate.match(/(\+|-)([0-9]+)years?/);
|
|
72
|
-
|
|
73
|
-
if ( Any.isEmpty(year) === false && year[1] === '+' ) {
|
|
74
|
-
this.moment.add(year[2], 'year');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if ( Any.isEmpty(year) === false && year[1] === '-' ) {
|
|
78
|
-
this.moment.subtract(year[2], 'year');
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
static make(date = null, format = 'YYYY-MM-DD HH:mm:ss')
|
|
85
|
-
{
|
|
86
|
-
return new Now(date, format);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
get()
|
|
90
|
-
{
|
|
91
|
-
return this.moment;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
valid()
|
|
95
|
-
{
|
|
96
|
-
return ! Any.isEmpty(this.initialDate) &&
|
|
97
|
-
Any.global().moment(this.initialDate).isValid();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
clone()
|
|
101
|
-
{
|
|
102
|
-
return new Now(this.moment.toDate());
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
code(format = 'X')
|
|
106
|
-
{
|
|
107
|
-
return Num.int(this.format(format, true));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
format(format = 'YYYY-MM-DD HH:mm:ss', force = false)
|
|
111
|
-
{
|
|
112
|
-
if ( ! this.valid() && ! force ) {
|
|
113
|
-
return '';
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return this.moment.format(format);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
before(before = null)
|
|
120
|
-
{
|
|
121
|
-
return this.code() < Now.make(before).code();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
beforeDate(before = null)
|
|
125
|
-
{
|
|
126
|
-
return this.code('YYYYMMDD') <
|
|
127
|
-
Now.make(before).code('YYYYMMDD');
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
beforeTime(before = null)
|
|
131
|
-
{
|
|
132
|
-
return this.code('HHmmss') <
|
|
133
|
-
Now.make(before).code('HHmmss');
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
after(after = null)
|
|
137
|
-
{
|
|
138
|
-
return this.code() > Now.make(after).code();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
afterDate(after = null)
|
|
142
|
-
{
|
|
143
|
-
return this.code('YYYYMMDD') >
|
|
144
|
-
Now.make(after).code('YYYYMMDD');
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
afterTime(after = null)
|
|
148
|
-
{
|
|
149
|
-
return this.code('HHmmss') >
|
|
150
|
-
Now.make(after).code('HHmmss');
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
equal(equal = null, format = 'X')
|
|
154
|
-
{
|
|
155
|
-
return this.code(format) ===
|
|
156
|
-
Now.make(equal).code(format);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
equalDate(equal = null, format = 'YYYYMMDD')
|
|
160
|
-
{
|
|
161
|
-
return this.equal(equal, format);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
equalTime(equal = null, format = 'HHmmss')
|
|
165
|
-
{
|
|
166
|
-
return this.equal(equal, format);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
between(fromDate = null, toDate = null, format = 'YYYYMMDD')
|
|
170
|
-
{
|
|
171
|
-
if ( Now.make(toDate).code(format) < Now.make(fromDate).code(format) ) {
|
|
172
|
-
return this.after(toDate, format) && this.before(fromDate, format) &&
|
|
173
|
-
! this.equal(toDate, format) && ! this.equal(fromDate, format);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return this.after(fromDate, format) && this.before(toDate, format) &&
|
|
177
|
-
! this.equal(toDate, format) && ! this.equal(fromDate, format);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
decade()
|
|
181
|
-
{
|
|
182
|
-
return Math.floor(this.year() / 10) * 10;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
prevDecade()
|
|
186
|
-
{
|
|
187
|
-
return this.clone().subDecades(1);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
nextDecade()
|
|
191
|
-
{
|
|
192
|
-
return this.clone().addDecades(1);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
addDecades(count = 1)
|
|
196
|
-
{
|
|
197
|
-
return this.year(this.moment.year() + (count * 10));
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
subDecades(count = 1)
|
|
201
|
-
{
|
|
202
|
-
return this.year(this.moment.year() - (count * 10));
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
year(year = null)
|
|
206
|
-
{
|
|
207
|
-
if ( year === null ) {
|
|
208
|
-
return this.moment.year();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
this.moment.year(year);
|
|
212
|
-
|
|
213
|
-
return this;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
prevYear()
|
|
217
|
-
{
|
|
218
|
-
return this.clone().year(this.year() - 1);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
nextYear()
|
|
222
|
-
{
|
|
223
|
-
return this.clone().year(this.year() + 1);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
addYears(count = 1)
|
|
227
|
-
{
|
|
228
|
-
return this.year(this.year() + count);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
subYears(count = 1)
|
|
232
|
-
{
|
|
233
|
-
return this.year(this.year() - count);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
month(month = null)
|
|
237
|
-
{
|
|
238
|
-
if ( month === null ) {
|
|
239
|
-
return this.moment.month();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
this.moment.month(month);
|
|
243
|
-
|
|
244
|
-
return this;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
addMonths(count = 1)
|
|
248
|
-
{
|
|
249
|
-
return this.month(this.month() + count);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
subMonths(count = 1)
|
|
253
|
-
{
|
|
254
|
-
return this.month(this.month() - count);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
prevMonth()
|
|
258
|
-
{
|
|
259
|
-
return this.clone().month(this.month() - 1);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
nextMonth()
|
|
263
|
-
{
|
|
264
|
-
return this.clone().month(this.month() + 1);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
date(date = null)
|
|
268
|
-
{
|
|
269
|
-
if ( date === null ) {
|
|
270
|
-
return this.moment.date();
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
this.moment.date(date);
|
|
274
|
-
|
|
275
|
-
return this;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
addDates(count = 1)
|
|
279
|
-
{
|
|
280
|
-
return this.date(this.date() + count);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
subDates(count = 1)
|
|
284
|
-
{
|
|
285
|
-
return this.date(this.date() - count);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
prevDate()
|
|
289
|
-
{
|
|
290
|
-
return this.clone().date(this.date() - 1);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
nextDate()
|
|
294
|
-
{
|
|
295
|
-
return this.clone().date(this.date() + 1);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
lastDate()
|
|
299
|
-
{
|
|
300
|
-
return this.prevMonth().date(0).date();
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
day(day = null)
|
|
304
|
-
{
|
|
305
|
-
if ( day === null ) {
|
|
306
|
-
return this.moment.day();
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
this.moment.day(day);
|
|
310
|
-
|
|
311
|
-
return this;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
hour(hour = null)
|
|
315
|
-
{
|
|
316
|
-
if ( hour === null ) {
|
|
317
|
-
return this.moment.hour();
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
this.moment.hour(hour);
|
|
321
|
-
|
|
322
|
-
return this;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
addHour(count = 1)
|
|
326
|
-
{
|
|
327
|
-
return this.hour(this.hour() + count);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
subHour(count = 1)
|
|
331
|
-
{
|
|
332
|
-
return this.hour(this.hour() - count);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
prevHour()
|
|
336
|
-
{
|
|
337
|
-
return this.clone().hour(this.hour() - 1);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
nextHour()
|
|
341
|
-
{
|
|
342
|
-
return this.clone().hour(this.hour() + 1);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
minute(minute = null)
|
|
346
|
-
{
|
|
347
|
-
if ( minute === null ) {
|
|
348
|
-
return this.moment.minute();
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
this.moment.minute(minute);
|
|
352
|
-
|
|
353
|
-
return this;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
addMinute(count = 1)
|
|
357
|
-
{
|
|
358
|
-
return this.minute(this.minute() + count);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
subMinute(count = 1)
|
|
362
|
-
{
|
|
363
|
-
return this.minute(this.minute() - count);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
prevMinute()
|
|
367
|
-
{
|
|
368
|
-
return this.clone().minute(this.minute() - 1);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
nextMinute()
|
|
372
|
-
{
|
|
373
|
-
return this.clone().minute(this.minute() + 1);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
second(second = null)
|
|
377
|
-
{
|
|
378
|
-
if ( second === null ) {
|
|
379
|
-
return this.moment.second();
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
this.moment.second(second);
|
|
383
|
-
|
|
384
|
-
return this;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
addSecond(count = 1)
|
|
388
|
-
{
|
|
389
|
-
return this.second(this.second() + count);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
subSecond(count = 1)
|
|
393
|
-
{
|
|
394
|
-
return this.second(this.second() - count);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
prevSecond()
|
|
398
|
-
{
|
|
399
|
-
return this.clone().second(this.second() - 1);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
nextSecond()
|
|
403
|
-
{
|
|
404
|
-
return this.clone().second(this.second() + 1);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
humanDay()
|
|
408
|
-
{
|
|
409
|
-
return this.day();
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
humanMonth()
|
|
413
|
-
{
|
|
414
|
-
return this.month();
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
getMonths()
|
|
418
|
-
{
|
|
419
|
-
return Arr.make(12).map((month) => {
|
|
420
|
-
return this.clone().month(month - 1);
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
getYears()
|
|
425
|
-
{
|
|
426
|
-
return Arr.make(10).map((year) => {
|
|
427
|
-
return this.clone().year(this.decade() + year - 1);
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
getYearsGrid(size = 12)
|
|
432
|
-
{
|
|
433
|
-
return Arr.make(size).map((year) => {
|
|
434
|
-
return this.clone().year((Math.floor(this.year() / size)
|
|
435
|
-
* size) + year - 1);
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
getDates()
|
|
440
|
-
{
|
|
441
|
-
return Arr.make(this.lastDate()).map((date) => {
|
|
442
|
-
return this.clone().date(date);
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
getDatesRange(target = null)
|
|
447
|
-
{
|
|
448
|
-
let range = [], targetNow = Now.make(target);
|
|
449
|
-
|
|
450
|
-
if ( this.afterDate(target) ) {
|
|
451
|
-
|
|
452
|
-
for ( let day = targetNow; ! day.equalDate(this); day = day.nextDate() ) {
|
|
453
|
-
Arr.push(range, day);
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
Arr.push(range, this);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
if ( this.beforeDate(target) ) {
|
|
460
|
-
|
|
461
|
-
for ( let day = this; ! day.equalDate(targetNow); day = day.nextDate() ) {
|
|
462
|
-
Arr.push(range, day);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
Arr.push(range, targetNow);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
if ( range.length === 0 ) {
|
|
469
|
-
range = [this];
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
return range;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
getDatesGrid(start = 1, end = 0)
|
|
476
|
-
{
|
|
477
|
-
let dates = this.getDates(), before = [], after = [];
|
|
478
|
-
|
|
479
|
-
let prev = Arr.first(dates);
|
|
480
|
-
|
|
481
|
-
for (let day = prev.day(); prev.day() !== start; day = prev.day()) {
|
|
482
|
-
Arr.prepend(before, prev = prev.prevDate());
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
let next = Arr.last(dates);
|
|
486
|
-
|
|
487
|
-
for (let day = next.day(); next.day() !== end; day = next.day()) {
|
|
488
|
-
Arr.append(after, next = next.nextDate());
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
return Arr.merge(before, dates, after);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
getHours(interval = 1)
|
|
495
|
-
{
|
|
496
|
-
return Arr.make(24 / interval).map((val, hour) => {
|
|
497
|
-
return this.clone().hour(hour * interval);
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
getMinutes(interval = 1)
|
|
502
|
-
{
|
|
503
|
-
return Arr.make(60 / interval).map((val, minute) => {
|
|
504
|
-
return this.clone().minute(minute * interval);
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
getSeconds(interval = 1)
|
|
509
|
-
{
|
|
510
|
-
return Arr.make(60 / interval).map((val, second) => {
|
|
511
|
-
return this.clone().second(second * interval);
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
resetTime()
|
|
516
|
-
{
|
|
517
|
-
this.hour(0);
|
|
518
|
-
this.minute(0);
|
|
519
|
-
this.second(0);
|
|
520
|
-
|
|
521
|
-
return this;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
applyDate(now, format = 'YYYY-MM-DD HH:mm:ss')
|
|
525
|
-
{
|
|
526
|
-
now = Now.make(now, format);
|
|
527
|
-
|
|
528
|
-
this.year(now.year());
|
|
529
|
-
this.month(now.month());
|
|
530
|
-
this.date(now.date());
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
applyTime(now, format = 'YYYY-MM-DD HH:mm:ss')
|
|
534
|
-
{
|
|
535
|
-
now = Now.make(now, format);
|
|
536
|
-
|
|
537
|
-
this.hour(now.hour());
|
|
538
|
-
this.minute(now.minute());
|
|
539
|
-
this.second(now.second());
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
export default Now;
|
package/src/utility/number.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { Any, Arr, Obj } from "../index.js"
|
|
2
|
-
|
|
3
|
-
export class Num
|
|
4
|
-
{
|
|
5
|
-
static int(num)
|
|
6
|
-
{
|
|
7
|
-
return !Any.isString(num) ? parseInt(num) :
|
|
8
|
-
parseInt(num.replace('px', ''));
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static float(num)
|
|
12
|
-
{
|
|
13
|
-
return !Any.isString(num) ? parseFloat(num) :
|
|
14
|
-
parseFloat(num.replace('px', ''));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
static ceil(num)
|
|
18
|
-
{
|
|
19
|
-
return Math.ceil(num);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static round(num)
|
|
23
|
-
{
|
|
24
|
-
return Math.round(num);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
static floor(num)
|
|
28
|
-
{
|
|
29
|
-
return Math.floor(num);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
static fixed(num, fixed = 2)
|
|
33
|
-
{
|
|
34
|
-
return this.float(num).toFixed(fixed);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
static random(start = 0, end = 100)
|
|
38
|
-
{
|
|
39
|
-
return Math.floor((Math.random() * (end + 1)) + start);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
static matrix(num, limit = 10, base = [])
|
|
43
|
-
{
|
|
44
|
-
let value = 0;
|
|
45
|
-
|
|
46
|
-
for ( let i = 20; i >= 0; i -- ) {
|
|
47
|
-
if ( num >= (value = Math.pow(2, i)) ) {
|
|
48
|
-
base.push(value);
|
|
49
|
-
num -= value;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return base;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
static combine(arr)
|
|
57
|
-
{
|
|
58
|
-
return Arr.reduce(arr, (acc, val) => acc + val, 0);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
static distance(cord1, cord2, miles = false)
|
|
62
|
-
{
|
|
63
|
-
let defaultCord = {
|
|
64
|
-
lat: 0, lng: 0
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
cord1 = Obj.assign({}, defaultCord, cord1);
|
|
68
|
-
cord2 = Obj.assign({}, defaultCord, cord2);
|
|
69
|
-
|
|
70
|
-
let radlat1 = (Math.PI * this.float(cord1.lat)) / 180;
|
|
71
|
-
let radlat2 = (Math.PI * this.float(cord2.lat)) / 180;
|
|
72
|
-
|
|
73
|
-
let theta = this.float(cord1.lng) - this.float(cord2.lng);
|
|
74
|
-
let radtheta = (Math.PI * theta) / 180;
|
|
75
|
-
|
|
76
|
-
let dist = Math.sin(radlat1) * Math.sin(radlat2) +
|
|
77
|
-
Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
|
|
78
|
-
|
|
79
|
-
if ( dist > 1 ) {
|
|
80
|
-
dist = 1;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
dist = (Math.acos(dist) * 180) / Math.PI * 60 * 1.1515;
|
|
84
|
-
|
|
85
|
-
if ( !miles ) {
|
|
86
|
-
dist = dist * 1.609344;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return dist;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
static format(num, decimal = '.', thousand = ',', fixed = null)
|
|
93
|
-
{
|
|
94
|
-
if ( num === null ) {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
let value = num.toString();
|
|
99
|
-
|
|
100
|
-
if ( fixed !== null && fixed !== - 1 ) {
|
|
101
|
-
value = Any.float(num).toFixed(fixed);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let [totals, minals] = [
|
|
105
|
-
value.replace(/\.[0-9]+$/, ''), value.replace(/^[0-9\-]+\./, '')
|
|
106
|
-
];
|
|
107
|
-
|
|
108
|
-
let splits = Arr.reduce(totals.split('').reverse(), (result, val, key) => {
|
|
109
|
-
|
|
110
|
-
let index = Math.floor(key / 3);
|
|
111
|
-
|
|
112
|
-
result[index] = index === key / 3 ?
|
|
113
|
-
val : result[index] = val + result[index];
|
|
114
|
-
|
|
115
|
-
return result;
|
|
116
|
-
}, []);
|
|
117
|
-
|
|
118
|
-
let result = splits.reverse().join(thousand);
|
|
119
|
-
|
|
120
|
-
if ( fixed !== - 1 && fixed !== 0 && value.match(/\./) ) {
|
|
121
|
-
result += decimal + minals;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return result;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export default Num;
|