nhb-toolbox 3.6.1 → 3.6.3
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/date/Chronos.d.ts +56 -19
- package/dist/date/Chronos.d.ts.map +1 -1
- package/dist/date/Chronos.js +110 -27
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +15 -0
- package/package.json +1 -1
package/dist/date/Chronos.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ export declare class Chronos {
|
|
|
58
58
|
* * Formats the date into a custom string format (local time).
|
|
59
59
|
*
|
|
60
60
|
* @param format - The desired format (Default format is `dd, MMM DD, YYYY HH:mm:ss:mss` = `Sun, Apr 06, 2025 16:11:55:379`).
|
|
61
|
-
* @param useUTC - Optional `useUTC` to get the formatted time using UTC Offset, defaults to `false`.
|
|
61
|
+
* @param useUTC - Optional `useUTC` to get the formatted time using UTC Offset, defaults to `false`. Equivalent to `formatUTC()` method if set to `true`.
|
|
62
62
|
* @returns Formatted date string in desired format (in local time unless `useUTC` passed as `true`).
|
|
63
63
|
*/
|
|
64
64
|
format(format?: string, useUTC?: boolean): string;
|
|
@@ -69,12 +69,42 @@ export declare class Chronos {
|
|
|
69
69
|
* @returns Formatted date string in desired format (UTC time).
|
|
70
70
|
*/
|
|
71
71
|
formatUTC(format?: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* * Adds seconds and returns a new immutable instance.
|
|
74
|
+
* @param seconds - Number of seconds to add.
|
|
75
|
+
* @returns A new `Chronos` instance with the updated date.
|
|
76
|
+
*/
|
|
77
|
+
addSeconds(seconds: number): Chronos;
|
|
78
|
+
/**
|
|
79
|
+
* * Adds minutes and returns a new immutable instance.
|
|
80
|
+
* @param minutes - Number of minutes to add.
|
|
81
|
+
* @returns A new `Chronos` instance with the updated date.
|
|
82
|
+
*/
|
|
83
|
+
addMinutes(minutes: number): Chronos;
|
|
84
|
+
/**
|
|
85
|
+
* * Adds hours and returns a new immutable instance.
|
|
86
|
+
* @param hours - Number of hours to add.
|
|
87
|
+
* @returns A new `Chronos` instance with the updated date.
|
|
88
|
+
*/
|
|
89
|
+
addHours(hours: number): Chronos;
|
|
72
90
|
/**
|
|
73
91
|
* * Adds days and returns a new immutable instance.
|
|
74
92
|
* @param days - Number of days to add.
|
|
75
93
|
* @returns A new `Chronos` instance with the updated date.
|
|
76
94
|
*/
|
|
77
95
|
addDays(days: number): Chronos;
|
|
96
|
+
/**
|
|
97
|
+
* * Adds months and returns a new immutable instance.
|
|
98
|
+
* @param months - Number of months to add.
|
|
99
|
+
* @returns A new `Chronos` instance with the updated date.
|
|
100
|
+
*/
|
|
101
|
+
addMonths(months: number): Chronos;
|
|
102
|
+
/**
|
|
103
|
+
* * Adds years and returns a new immutable instance.
|
|
104
|
+
* @param years - Number of years to add.
|
|
105
|
+
* @returns A new `Chronos` instance with the updated date.
|
|
106
|
+
*/
|
|
107
|
+
addYears(years: number): Chronos;
|
|
78
108
|
/**
|
|
79
109
|
* * Subtracts days and returns a new immutable instance.
|
|
80
110
|
* @param days - Number of days to subtract.
|
|
@@ -102,27 +132,30 @@ export declare class Chronos {
|
|
|
102
132
|
/** - Checks if the current date is yesterday. */
|
|
103
133
|
isYesterday(): boolean;
|
|
104
134
|
/**
|
|
105
|
-
* * Returns full time difference from now (or specified time)
|
|
106
|
-
*
|
|
107
|
-
* @
|
|
135
|
+
* * Returns full time difference from now (or a specified time) down to a given level.
|
|
136
|
+
*
|
|
137
|
+
* @param level Determines the smallest unit to include in the output (e.g., 'minute' will show up to minutes, ignoring seconds). Defaults to `minute`.
|
|
138
|
+
* @param withSuffixPrefix If `true`, adds `"in"` or `"ago"` depending on whether the time is in the future or past. Defaults to `true`.
|
|
139
|
+
* @param time An optional time value to compare with (`string`, `number`, `Date`, or `Chronos` instance). Defaults to `now`.
|
|
140
|
+
* @returns The difference as a human-readable string, e.g., `2 years 1 month 9 days 18 hours 56 minutes ago`.
|
|
108
141
|
*/
|
|
109
|
-
fromNow(time?: string | number | Date | Chronos): string;
|
|
142
|
+
fromNow(level?: Exclude<TimeUnit, 'millisecond'>, withSuffixPrefix?: boolean, time?: string | number | Date | Chronos): string;
|
|
110
143
|
/**
|
|
111
144
|
* * Returns the number of full years between the input date and now.
|
|
112
|
-
* @param time Optional time to compare with the date/time.
|
|
113
|
-
* @returns The difference in number.
|
|
145
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
146
|
+
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
114
147
|
*/
|
|
115
148
|
getRelativeYear(time?: string | number | Date | Chronos): number;
|
|
116
149
|
/**
|
|
117
150
|
* * Returns the number of full months between the input date and now.
|
|
118
|
-
* @param time Optional time to compare with the date/time.
|
|
119
|
-
* @returns The difference in number.
|
|
151
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
152
|
+
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
120
153
|
*/
|
|
121
154
|
getRelativeMonth(time?: string | number | Date | Chronos): number;
|
|
122
155
|
/**
|
|
123
156
|
* * Determines if the given date is today, tomorrow, yesterday or any relative day.
|
|
124
157
|
* @param date - The date to compare (Date object).
|
|
125
|
-
* @param time Optional time to compare with the date/time.
|
|
158
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
126
159
|
* @returns
|
|
127
160
|
* - `-1` if the date is yesterday.
|
|
128
161
|
* - `0` if the date is today.
|
|
@@ -132,30 +165,34 @@ export declare class Chronos {
|
|
|
132
165
|
getRelativeDay(time?: string | number | Date | Chronos): number;
|
|
133
166
|
/**
|
|
134
167
|
* * Returns the number of full hours between the input date and now.
|
|
135
|
-
* @param time Optional time to compare with the date/time.
|
|
136
|
-
* @returns The difference in number.
|
|
168
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
169
|
+
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
137
170
|
*/
|
|
138
171
|
getRelativeHour(time?: string | number | Date | Chronos): number;
|
|
139
172
|
/**
|
|
140
173
|
* * Returns the number of full minutes between the input date and now.
|
|
141
|
-
* @param time Optional time to compare with the date/time.
|
|
142
|
-
* @returns The difference in number.
|
|
174
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
175
|
+
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
143
176
|
*/
|
|
144
177
|
getRelativeMinute(time?: string | number | Date | Chronos): number;
|
|
145
178
|
/**
|
|
146
179
|
* * Returns the number of full seconds between the input date and now.
|
|
147
|
-
* @param time Optional time to compare with the date/time.
|
|
148
|
-
* @returns The difference in number.
|
|
180
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
181
|
+
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
149
182
|
*/
|
|
150
183
|
getRelativeSecond(time?: string | number | Date | Chronos): number;
|
|
151
|
-
/**
|
|
184
|
+
/**
|
|
185
|
+
* * Returns the number of milliseconds between the input date and now.
|
|
186
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
187
|
+
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
188
|
+
*/
|
|
152
189
|
getRelativeMilliSecond(time?: string | number | Date | Chronos): number;
|
|
153
190
|
/**
|
|
154
191
|
* * Compares the stored date with now, returning the difference in the specified unit.
|
|
155
192
|
*
|
|
156
193
|
* @param unit The time unit to compare by. Defaults to 'minute'.
|
|
157
|
-
* @param time Optional time to compare with the date/time.
|
|
158
|
-
* @returns The difference in number.
|
|
194
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
195
|
+
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
159
196
|
*/
|
|
160
197
|
compare(unit?: TimeUnit, time?: string | number | Date | Chronos): number;
|
|
161
198
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[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AC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM;IAe/D;;;;OAIG;IACH,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM;IAKhE;;;;OAIG;IACH,iBAAiB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM;IAKlE;;;;OAIG;IACH,iBAAiB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM;IAKlE;;;;OAIG;IACH,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM;IAIvE;;;;;;OAMG;IACH,OAAO,CACN,IAAI,GAAE,QAAmB,EACzB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GACrC,MAAM;CAoBT"}
|
package/dist/date/Chronos.js
CHANGED
|
@@ -180,7 +180,7 @@ export class Chronos {
|
|
|
180
180
|
* * Formats the date into a custom string format (local time).
|
|
181
181
|
*
|
|
182
182
|
* @param format - The desired format (Default format is `dd, MMM DD, YYYY HH:mm:ss:mss` = `Sun, Apr 06, 2025 16:11:55:379`).
|
|
183
|
-
* @param useUTC - Optional `useUTC` to get the formatted time using UTC Offset, defaults to `false`.
|
|
183
|
+
* @param useUTC - Optional `useUTC` to get the formatted time using UTC Offset, defaults to `false`. Equivalent to `formatUTC()` method if set to `true`.
|
|
184
184
|
* @returns Formatted date string in desired format (in local time unless `useUTC` passed as `true`).
|
|
185
185
|
*/
|
|
186
186
|
format(format = 'dd, MMM DD, YYYY HH:mm:ss:mss', useUTC = false) {
|
|
@@ -195,6 +195,36 @@ export class Chronos {
|
|
|
195
195
|
formatUTC(format = 'dd, MMM DD, YYYY HH:mm:ss:mss') {
|
|
196
196
|
return this.#format(format, true);
|
|
197
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* * Adds seconds and returns a new immutable instance.
|
|
200
|
+
* @param seconds - Number of seconds to add.
|
|
201
|
+
* @returns A new `Chronos` instance with the updated date.
|
|
202
|
+
*/
|
|
203
|
+
addSeconds(seconds) {
|
|
204
|
+
const newDate = new Date(this.#date);
|
|
205
|
+
newDate.setSeconds(newDate.getSeconds() + seconds);
|
|
206
|
+
return new Chronos(newDate);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* * Adds minutes and returns a new immutable instance.
|
|
210
|
+
* @param minutes - Number of minutes to add.
|
|
211
|
+
* @returns A new `Chronos` instance with the updated date.
|
|
212
|
+
*/
|
|
213
|
+
addMinutes(minutes) {
|
|
214
|
+
const newDate = new Date(this.#date);
|
|
215
|
+
newDate.setMinutes(newDate.getMinutes() + minutes);
|
|
216
|
+
return new Chronos(newDate);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* * Adds hours and returns a new immutable instance.
|
|
220
|
+
* @param hours - Number of hours to add.
|
|
221
|
+
* @returns A new `Chronos` instance with the updated date.
|
|
222
|
+
*/
|
|
223
|
+
addHours(hours) {
|
|
224
|
+
const newDate = new Date(this.#date);
|
|
225
|
+
newDate.setHours(newDate.getHours() + hours);
|
|
226
|
+
return new Chronos(newDate);
|
|
227
|
+
}
|
|
198
228
|
/**
|
|
199
229
|
* * Adds days and returns a new immutable instance.
|
|
200
230
|
* @param days - Number of days to add.
|
|
@@ -205,6 +235,26 @@ export class Chronos {
|
|
|
205
235
|
newDate.setDate(newDate.getDate() + days);
|
|
206
236
|
return new Chronos(newDate);
|
|
207
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* * Adds months and returns a new immutable instance.
|
|
240
|
+
* @param months - Number of months to add.
|
|
241
|
+
* @returns A new `Chronos` instance with the updated date.
|
|
242
|
+
*/
|
|
243
|
+
addMonths(months) {
|
|
244
|
+
const newDate = new Date(this.#date);
|
|
245
|
+
newDate.setMonth(newDate.getMonth() + months);
|
|
246
|
+
return new Chronos(newDate);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* * Adds years and returns a new immutable instance.
|
|
250
|
+
* @param years - Number of years to add.
|
|
251
|
+
* @returns A new `Chronos` instance with the updated date.
|
|
252
|
+
*/
|
|
253
|
+
addYears(years) {
|
|
254
|
+
const newDate = new Date(this.#date);
|
|
255
|
+
newDate.setFullYear(newDate.getFullYear() + years);
|
|
256
|
+
return new Chronos(newDate);
|
|
257
|
+
}
|
|
208
258
|
/**
|
|
209
259
|
* * Subtracts days and returns a new immutable instance.
|
|
210
260
|
* @param days - Number of days to subtract.
|
|
@@ -254,11 +304,14 @@ export class Chronos {
|
|
|
254
304
|
return this.getRelativeDay() === -1;
|
|
255
305
|
}
|
|
256
306
|
/**
|
|
257
|
-
* * Returns full time difference from now (or specified time)
|
|
258
|
-
*
|
|
259
|
-
* @
|
|
307
|
+
* * Returns full time difference from now (or a specified time) down to a given level.
|
|
308
|
+
*
|
|
309
|
+
* @param level Determines the smallest unit to include in the output (e.g., 'minute' will show up to minutes, ignoring seconds). Defaults to `minute`.
|
|
310
|
+
* @param withSuffixPrefix If `true`, adds `"in"` or `"ago"` depending on whether the time is in the future or past. Defaults to `true`.
|
|
311
|
+
* @param time An optional time value to compare with (`string`, `number`, `Date`, or `Chronos` instance). Defaults to `now`.
|
|
312
|
+
* @returns The difference as a human-readable string, e.g., `2 years 1 month 9 days 18 hours 56 minutes ago`.
|
|
260
313
|
*/
|
|
261
|
-
fromNow(time) {
|
|
314
|
+
fromNow(level = 'minute', withSuffixPrefix = true, time) {
|
|
262
315
|
const now = this.#toNewDate(time);
|
|
263
316
|
const target = this.#date;
|
|
264
317
|
const isFuture = target > now;
|
|
@@ -292,25 +345,51 @@ export class Chronos {
|
|
|
292
345
|
months += 12;
|
|
293
346
|
years--;
|
|
294
347
|
}
|
|
348
|
+
const unitOrder = [
|
|
349
|
+
'year',
|
|
350
|
+
'month',
|
|
351
|
+
'day',
|
|
352
|
+
'hour',
|
|
353
|
+
'minute',
|
|
354
|
+
'second',
|
|
355
|
+
];
|
|
356
|
+
const lvlIdx = unitOrder.indexOf(level);
|
|
295
357
|
const parts = [];
|
|
296
|
-
if (years > 0)
|
|
358
|
+
if (lvlIdx >= 0 && years > 0 && lvlIdx >= unitOrder.indexOf('year')) {
|
|
297
359
|
parts.push(`${years} year${years > 1 ? 's' : ''}`);
|
|
298
|
-
|
|
360
|
+
}
|
|
361
|
+
if (lvlIdx >= unitOrder.indexOf('month') && months > 0) {
|
|
299
362
|
parts.push(`${months} month${months > 1 ? 's' : ''}`);
|
|
300
|
-
|
|
363
|
+
}
|
|
364
|
+
if (lvlIdx >= unitOrder.indexOf('day') && days > 0) {
|
|
301
365
|
parts.push(`${days} day${days > 1 ? 's' : ''}`);
|
|
302
|
-
|
|
366
|
+
}
|
|
367
|
+
if (lvlIdx >= unitOrder.indexOf('hour') && hours > 0) {
|
|
303
368
|
parts.push(`${hours} hour${hours > 1 ? 's' : ''}`);
|
|
304
|
-
|
|
369
|
+
}
|
|
370
|
+
if (lvlIdx >= unitOrder.indexOf('minute') && minutes > 0) {
|
|
305
371
|
parts.push(`${minutes} minute${minutes > 1 ? 's' : ''}`);
|
|
306
|
-
|
|
372
|
+
}
|
|
373
|
+
if (lvlIdx >= unitOrder.indexOf('second') &&
|
|
374
|
+
(seconds > 0 || parts.length === 0)) {
|
|
307
375
|
parts.push(`${seconds} second${seconds !== 1 ? 's' : ''}`);
|
|
308
|
-
|
|
376
|
+
}
|
|
377
|
+
let prefix = '';
|
|
378
|
+
let suffix = '';
|
|
379
|
+
if (withSuffixPrefix) {
|
|
380
|
+
if (isFuture) {
|
|
381
|
+
prefix = 'in ';
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
suffix = ' ago';
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return `${prefix}${parts.join(' ')}${suffix}`;
|
|
309
388
|
}
|
|
310
389
|
/**
|
|
311
390
|
* * Returns the number of full years between the input date and now.
|
|
312
|
-
* @param time Optional time to compare with the date/time.
|
|
313
|
-
* @returns The difference in number.
|
|
391
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
392
|
+
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
314
393
|
*/
|
|
315
394
|
getRelativeYear(time) {
|
|
316
395
|
const now = this.#toNewDate(time);
|
|
@@ -325,8 +404,8 @@ export class Chronos {
|
|
|
325
404
|
}
|
|
326
405
|
/**
|
|
327
406
|
* * Returns the number of full months between the input date and now.
|
|
328
|
-
* @param time Optional time to compare with the date/time.
|
|
329
|
-
* @returns The difference in number.
|
|
407
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
408
|
+
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
330
409
|
*/
|
|
331
410
|
getRelativeMonth(time) {
|
|
332
411
|
const now = this.#toNewDate(time);
|
|
@@ -341,7 +420,7 @@ export class Chronos {
|
|
|
341
420
|
/**
|
|
342
421
|
* * Determines if the given date is today, tomorrow, yesterday or any relative day.
|
|
343
422
|
* @param date - The date to compare (Date object).
|
|
344
|
-
* @param time Optional time to compare with the date/time.
|
|
423
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
345
424
|
* @returns
|
|
346
425
|
* - `-1` if the date is yesterday.
|
|
347
426
|
* - `0` if the date is today.
|
|
@@ -353,7 +432,7 @@ export class Chronos {
|
|
|
353
432
|
// Set the time of today to 00:00:00 for comparison purposes
|
|
354
433
|
today.setHours(0, 0, 0, 0);
|
|
355
434
|
// Normalize the input date to 00:00:00
|
|
356
|
-
const inputDate =
|
|
435
|
+
const inputDate = this.#date;
|
|
357
436
|
inputDate.setHours(0, 0, 0, 0);
|
|
358
437
|
const diffTime = inputDate.getTime() - today.getTime();
|
|
359
438
|
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
|
|
@@ -361,8 +440,8 @@ export class Chronos {
|
|
|
361
440
|
}
|
|
362
441
|
/**
|
|
363
442
|
* * Returns the number of full hours between the input date and now.
|
|
364
|
-
* @param time Optional time to compare with the date/time.
|
|
365
|
-
* @returns The difference in number.
|
|
443
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
444
|
+
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
366
445
|
*/
|
|
367
446
|
getRelativeHour(time) {
|
|
368
447
|
const diff = this.#date.getTime() - this.#toNewDate(time).getTime();
|
|
@@ -370,8 +449,8 @@ export class Chronos {
|
|
|
370
449
|
}
|
|
371
450
|
/**
|
|
372
451
|
* * Returns the number of full minutes between the input date and now.
|
|
373
|
-
* @param time Optional time to compare with the date/time.
|
|
374
|
-
* @returns The difference in number.
|
|
452
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
453
|
+
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
375
454
|
*/
|
|
376
455
|
getRelativeMinute(time) {
|
|
377
456
|
const diff = this.#date.getTime() - this.#toNewDate(time).getTime();
|
|
@@ -379,14 +458,18 @@ export class Chronos {
|
|
|
379
458
|
}
|
|
380
459
|
/**
|
|
381
460
|
* * Returns the number of full seconds between the input date and now.
|
|
382
|
-
* @param time Optional time to compare with the date/time.
|
|
383
|
-
* @returns The difference in number.
|
|
461
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
462
|
+
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
384
463
|
*/
|
|
385
464
|
getRelativeSecond(time) {
|
|
386
465
|
const diff = this.#date.getTime() - this.#toNewDate(time).getTime();
|
|
387
466
|
return Math.floor(diff / 1000);
|
|
388
467
|
}
|
|
389
|
-
/**
|
|
468
|
+
/**
|
|
469
|
+
* * Returns the number of milliseconds between the input date and now.
|
|
470
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
471
|
+
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
472
|
+
*/
|
|
390
473
|
getRelativeMilliSecond(time) {
|
|
391
474
|
return this.#date.getTime() - this.#toNewDate(time).getTime();
|
|
392
475
|
}
|
|
@@ -394,8 +477,8 @@ export class Chronos {
|
|
|
394
477
|
* * Compares the stored date with now, returning the difference in the specified unit.
|
|
395
478
|
*
|
|
396
479
|
* @param unit The time unit to compare by. Defaults to 'minute'.
|
|
397
|
-
* @param time Optional time to compare with the date/time.
|
|
398
|
-
* @returns The difference in number.
|
|
480
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
481
|
+
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
399
482
|
*/
|
|
400
483
|
compare(unit = 'minute', time) {
|
|
401
484
|
switch (unit) {
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export { convertObjectValues } from './object/convert';
|
|
|
29
29
|
export { generateQueryParams, getQueryParams, updateQueryParam, } from './dom/query';
|
|
30
30
|
export { copyToClipboard, smoothScrollTo, toggleFullScreen } from './dom/utils';
|
|
31
31
|
export { getFromLocalStorage, getFromSessionStorage, removeFromLocalStorage, removeFromSessionStorage, saveToLocalStorage, saveToSessionStorage, } from './dom/storage';
|
|
32
|
-
export { convertArrayToString, debounceAction, isDeepEqual, throttleAction, } from './utils';
|
|
32
|
+
export { convertArrayToString, debounceAction, isDeepEqual, throttleAction, countClassMethods, } from './utils';
|
|
33
33
|
export { isBoolean, isFalsy, isInteger, isNonEmptyString, isNull, isNumber, isPositiveInteger, isPrimitive, isString, isSymbol, isTruthy, isUndefined, } from './guards/primitives';
|
|
34
34
|
export { isReturningPromise as doesReturnPromise, isArray, isArrayOfType, isValidArray as isArrayWithLength, isBigInt, isDate, isEmptyObject, isEmptyObject as isEmptyObjectGuard, isError, isFunction, isJSON, isJSON as isJSONObject, isMap, isNotEmptyObject, isObject, isEmptyObject as isObjectEmpty, isObjectWithKeys, isPromise, isRegExp, isRegExp as isRegularExpression, isReturningPromise, isSet, isValidArray, isJSON as isValidJSON, isMap as isValidMap, isNotEmptyObject as isValidObject, isSet as isValidSet, } from './guards/non-primitives';
|
|
35
35
|
export { isBase64, isBrowser, isDateString, isEmail, isEmailArray, isEnvironment, isEnvironment as isExpectedNodeENV, isIPAddress, isNode, isEnvironment as isNodeENV, isEnvironment as isNodeEnvironment, isNumericString, isPhoneNumber, isURL, isUUID, isEmail as isValidEmail, isURL as isValidURL, } from './guards/specials';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,cAAc,GACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EACN,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,aAAa,GACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,IAAI,mBAAmB,GAC7C,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACN,YAAY,IAAI,YAAY,EAC5B,YAAY,EACZ,YAAY,IAAI,YAAY,EAC5B,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,IAAI,YAAY,EAClC,kBAAkB,IAAI,mBAAmB,EACzC,kBAAkB,EAClB,eAAe,EACf,UAAU,IAAI,eAAe,EAC7B,aAAa,EACb,SAAS,EACT,UAAU,EACV,UAAU,IAAI,YAAY,GAC1B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,MAAM,EACN,MAAM,IAAI,YAAY,EACtB,WAAW,EACX,UAAU,EACV,KAAK,EACL,KAAK,IAAI,WAAW,EACpB,WAAW,IAAI,gBAAgB,EAC/B,WAAW,IAAI,sBAAsB,EAC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S,EACT,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,aAAa,EACb,aAAa,IAAI,iBAAiB,EAClC,WAAW,EACX,MAAM,EACN,aAAa,IAAI,SAAS,EAC1B,aAAa,IAAI,iBAAiB,EAClC,eAAe,EACf,aAAa,EACb,KAAK,EACL,MAAM,EACN,OAAO,IAAI,YAAY,EACvB,KAAK,IAAI,UAAU,GACnB,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -38,7 +38,7 @@ export { generateQueryParams, getQueryParams, updateQueryParam, } from './dom/qu
|
|
|
38
38
|
export { copyToClipboard, smoothScrollTo, toggleFullScreen } from './dom/utils';
|
|
39
39
|
export { getFromLocalStorage, getFromSessionStorage, removeFromLocalStorage, removeFromSessionStorage, saveToLocalStorage, saveToSessionStorage, } from './dom/storage';
|
|
40
40
|
// ! Other Utilities
|
|
41
|
-
export { convertArrayToString, debounceAction, isDeepEqual, throttleAction, } from './utils';
|
|
41
|
+
export { convertArrayToString, debounceAction, isDeepEqual, throttleAction, countClassMethods, } from './utils';
|
|
42
42
|
// ! Primitive Type Guards
|
|
43
43
|
export { isBoolean, isFalsy, isInteger, isNonEmptyString, isNull, isNumber, isPositiveInteger, isPrimitive, isString, isSymbol, isTruthy, isUndefined, } from './guards/primitives';
|
|
44
44
|
// ! Non-Primitive Type Guards
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -45,4 +45,11 @@ export declare const debounceAction: <T extends VoidFunction>(callback: T, delay
|
|
|
45
45
|
* window.addEventListener('resize', throttledResize);
|
|
46
46
|
*/
|
|
47
47
|
export declare const throttleAction: <T extends VoidFunction>(callback: T, delay?: number) => ThrottledFn<T>;
|
|
48
|
+
/**
|
|
49
|
+
* * Counts the number of instance methods defined on a class prototype.
|
|
50
|
+
*
|
|
51
|
+
* @param cls The class constructor (not an instance).
|
|
52
|
+
* @returns Number of methods directly defined on the class prototype.
|
|
53
|
+
*/
|
|
54
|
+
export declare function countClassMethods(cls: Function): number;
|
|
48
55
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAErE;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAG,OA6B3C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAC9B,CAAC,EAAE,cACC,MAAM,KACf,MAKF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,YAAY,YAC1C,CAAC,qBAET,SAAS,CAAC,CAAC,CAYb,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,YAAY,YAC1C,CAAC,qBAET,WAAW,CAAC,CAAC,CAWf,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAErE;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAG,OA6B3C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAC9B,CAAC,EAAE,cACC,MAAM,KACf,MAKF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,YAAY,YAC1C,CAAC,qBAET,SAAS,CAAC,CAAC,CAYb,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,YAAY,YAC1C,CAAC,qBAET,WAAW,CAAC,CAAC,CAWf,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAQvD"}
|
package/dist/utils/index.js
CHANGED
|
@@ -94,3 +94,18 @@ export const throttleAction = (callback, delay = 150) => {
|
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* * Counts the number of instance methods defined on a class prototype.
|
|
99
|
+
*
|
|
100
|
+
* @param cls The class constructor (not an instance).
|
|
101
|
+
* @returns Number of methods directly defined on the class prototype.
|
|
102
|
+
*/
|
|
103
|
+
export function countClassMethods(cls) {
|
|
104
|
+
const prototype = cls.prototype;
|
|
105
|
+
return Object.getOwnPropertyNames(prototype).filter((name) => {
|
|
106
|
+
if (name === 'constructor')
|
|
107
|
+
return false;
|
|
108
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
|
|
109
|
+
return !!descriptor && typeof descriptor.value === 'function';
|
|
110
|
+
}).length;
|
|
111
|
+
}
|
package/package.json
CHANGED