@naturalcycles/js-lib 14.184.0 → 14.185.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/datetime/localDate.d.ts +10 -1
- package/dist/datetime/localDate.js +13 -0
- package/dist/datetime/localTime.d.ts +10 -1
- package/dist/datetime/localTime.js +13 -0
- package/dist/object/object.util.d.ts +18 -0
- package/dist/object/object.util.js +25 -1
- package/dist/types.d.ts +2 -1
- package/dist-esm/datetime/localDate.js +13 -0
- package/dist-esm/datetime/localTime.js +13 -0
- package/dist-esm/object/object.util.js +23 -0
- package/package.json +6 -5
- package/src/datetime/localDate.ts +16 -0
- package/src/datetime/localTime.ts +16 -0
- package/src/object/object.util.ts +24 -0
- package/src/types.ts +2 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IsoDateString, IsoDateTimeString, UnixTimestampMillisNumber, UnixTimestampNumber } from '../types';
|
|
1
|
+
import type { IsoDateString, IsoDateTimeString, MonthId, UnixTimestampMillisNumber, UnixTimestampNumber } from '../types';
|
|
2
2
|
import { LocalTime } from './localTime';
|
|
3
3
|
export type LocalDateUnit = LocalDateUnitStrict | 'week';
|
|
4
4
|
export type LocalDateUnitStrict = 'year' | 'month' | 'day';
|
|
@@ -49,6 +49,14 @@ export declare class LocalDate {
|
|
|
49
49
|
isAfter(d: LocalDateInput, inclusive?: boolean): boolean;
|
|
50
50
|
isSameOrAfter(d: LocalDateInput): boolean;
|
|
51
51
|
isBetween(min: LocalDateInput, max: LocalDateInput, incl?: Inclusiveness): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Checks if this localDate is older than "today" by X units.
|
|
54
|
+
*
|
|
55
|
+
* Example:
|
|
56
|
+
*
|
|
57
|
+
* localDate(expirationDate).isOlderThan(5, 'day')
|
|
58
|
+
*/
|
|
59
|
+
isOlderThan(n: number, unit: LocalDateUnitStrict): boolean;
|
|
52
60
|
/**
|
|
53
61
|
* Returns 1 if this > d
|
|
54
62
|
* returns 0 if they are equal
|
|
@@ -88,6 +96,7 @@ export declare class LocalDate {
|
|
|
88
96
|
toISODateTime(): IsoDateTimeString;
|
|
89
97
|
toString(): IsoDateString;
|
|
90
98
|
toStringCompact(): string;
|
|
99
|
+
toMonthId(): MonthId;
|
|
91
100
|
unix(): UnixTimestampNumber;
|
|
92
101
|
unixMillis(): UnixTimestampMillisNumber;
|
|
93
102
|
toJSON(): IsoDateString;
|
|
@@ -179,6 +179,16 @@ class LocalDate {
|
|
|
179
179
|
return false;
|
|
180
180
|
return true;
|
|
181
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Checks if this localDate is older than "today" by X units.
|
|
184
|
+
*
|
|
185
|
+
* Example:
|
|
186
|
+
*
|
|
187
|
+
* localDate(expirationDate).isOlderThan(5, 'day')
|
|
188
|
+
*/
|
|
189
|
+
isOlderThan(n, unit) {
|
|
190
|
+
return this.isBefore(LocalDate.today().add(-n, unit));
|
|
191
|
+
}
|
|
182
192
|
/**
|
|
183
193
|
* Returns 1 if this > d
|
|
184
194
|
* returns 0 if they are equal
|
|
@@ -393,6 +403,9 @@ class LocalDate {
|
|
|
393
403
|
String(this.$day).padStart(2, '0'),
|
|
394
404
|
].join('');
|
|
395
405
|
}
|
|
406
|
+
toMonthId() {
|
|
407
|
+
return this.toString().slice(0, 7);
|
|
408
|
+
}
|
|
396
409
|
// May be not optimal, as LocalTime better suits it
|
|
397
410
|
unix() {
|
|
398
411
|
return Math.floor(this.toDate().valueOf() / 1000);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IsoDateString, IsoDateTimeString, UnixTimestampMillisNumber, UnixTimestampNumber } from '../types';
|
|
1
|
+
import type { IsoDateString, IsoDateTimeString, MonthId, UnixTimestampMillisNumber, UnixTimestampNumber } from '../types';
|
|
2
2
|
import type { Inclusiveness } from './localDate';
|
|
3
3
|
import { LocalDate } from './localDate';
|
|
4
4
|
export type LocalTimeUnit = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
|
|
@@ -87,6 +87,14 @@ export declare class LocalTime {
|
|
|
87
87
|
isAfter(d: LocalTimeInput, inclusive?: boolean): boolean;
|
|
88
88
|
isSameOrAfter(d: LocalTimeInput): boolean;
|
|
89
89
|
isBetween(min: LocalTimeInput, max: LocalTimeInput, incl?: Inclusiveness): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if this localTime is older than "now" by X units.
|
|
92
|
+
*
|
|
93
|
+
* Example:
|
|
94
|
+
*
|
|
95
|
+
* localTime(expirationDate).isOlderThan(5, 'day')
|
|
96
|
+
*/
|
|
97
|
+
isOlderThan(n: number, unit: LocalTimeUnit): boolean;
|
|
90
98
|
/**
|
|
91
99
|
* Returns 1 if this > d
|
|
92
100
|
* returns 0 if they are equal
|
|
@@ -120,6 +128,7 @@ export declare class LocalTime {
|
|
|
120
128
|
toStringCompact(seconds?: boolean): string;
|
|
121
129
|
toString(): string;
|
|
122
130
|
toJSON(): UnixTimestampNumber;
|
|
131
|
+
toMonthId(): MonthId;
|
|
123
132
|
format(fmt: Intl.DateTimeFormat | LocalTimeFormatter): string;
|
|
124
133
|
}
|
|
125
134
|
/**
|
|
@@ -357,6 +357,16 @@ class LocalTime {
|
|
|
357
357
|
return false;
|
|
358
358
|
return true;
|
|
359
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* Checks if this localTime is older than "now" by X units.
|
|
362
|
+
*
|
|
363
|
+
* Example:
|
|
364
|
+
*
|
|
365
|
+
* localTime(expirationDate).isOlderThan(5, 'day')
|
|
366
|
+
*/
|
|
367
|
+
isOlderThan(n, unit) {
|
|
368
|
+
return this.isBefore(LocalTime.now().add(-n, unit));
|
|
369
|
+
}
|
|
360
370
|
/**
|
|
361
371
|
* Returns 1 if this > d
|
|
362
372
|
* returns 0 if they are equal
|
|
@@ -480,6 +490,9 @@ class LocalTime {
|
|
|
480
490
|
toJSON() {
|
|
481
491
|
return this.unix();
|
|
482
492
|
}
|
|
493
|
+
toMonthId() {
|
|
494
|
+
return this.$date.toISOString().slice(0, 7);
|
|
495
|
+
}
|
|
483
496
|
format(fmt) {
|
|
484
497
|
if (fmt instanceof Intl.DateTimeFormat) {
|
|
485
498
|
return fmt.format(this.$date);
|
|
@@ -189,3 +189,21 @@ export declare function _has<T extends AnyObject>(obj: T, path: string): boolean
|
|
|
189
189
|
* Based on: https://github.com/substack/deep-freeze/blob/master/index.js
|
|
190
190
|
*/
|
|
191
191
|
export declare function _deepFreeze(o: any): void;
|
|
192
|
+
/**
|
|
193
|
+
* let target: T = { a: 'a', n: 1}
|
|
194
|
+
* let source: T = { a: 'a2', b: 'b' }
|
|
195
|
+
*
|
|
196
|
+
* _objectAssignExact(target, source)
|
|
197
|
+
*
|
|
198
|
+
* Does the same as `target = source`,
|
|
199
|
+
* except that it mutates the target to make it exactly the same as source,
|
|
200
|
+
* while keeping the reference to the same object.
|
|
201
|
+
*
|
|
202
|
+
* This way it can "propagate deletions".
|
|
203
|
+
* E.g source doesn't have the `n` property, so it'll be deleted from target.
|
|
204
|
+
* With normal Object.assign - it'll override the keys that `source` has, but not the
|
|
205
|
+
* "missing/deleted keys".
|
|
206
|
+
*
|
|
207
|
+
* To make mutation extra clear - function returns void (unlike Object.assign).
|
|
208
|
+
*/
|
|
209
|
+
export declare function _objectAssignExact<T extends AnyObject>(target: T, source: T): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._deepFreeze = exports._has = exports._set = exports._get = exports._invertMap = exports._invert = exports._unset = exports._deepTrim = exports._merge = exports._filterEmptyValues = exports._undefinedIfEmpty = exports._deepCopy = exports._objectNullValuesToUndefined = exports._findKeyByValue = exports._mapObject = exports._mapKeys = exports._mapValues = exports._filterObject = exports._filterEmptyArrays = exports._filterUndefinedValues = exports._filterNullishValues = exports._filterFalsyValues = exports._mask = exports._omit = exports._pick = void 0;
|
|
3
|
+
exports._objectAssignExact = exports._deepFreeze = exports._has = exports._set = exports._get = exports._invertMap = exports._invert = exports._unset = exports._deepTrim = exports._merge = exports._filterEmptyValues = exports._undefinedIfEmpty = exports._deepCopy = exports._objectNullValuesToUndefined = exports._findKeyByValue = exports._mapObject = exports._mapKeys = exports._mapValues = exports._filterObject = exports._filterEmptyArrays = exports._filterUndefinedValues = exports._filterNullishValues = exports._filterFalsyValues = exports._mask = exports._omit = exports._pick = void 0;
|
|
4
4
|
const is_util_1 = require("../is.util");
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
/**
|
|
@@ -384,3 +384,27 @@ function _deepFreeze(o) {
|
|
|
384
384
|
});
|
|
385
385
|
}
|
|
386
386
|
exports._deepFreeze = _deepFreeze;
|
|
387
|
+
/**
|
|
388
|
+
* let target: T = { a: 'a', n: 1}
|
|
389
|
+
* let source: T = { a: 'a2', b: 'b' }
|
|
390
|
+
*
|
|
391
|
+
* _objectAssignExact(target, source)
|
|
392
|
+
*
|
|
393
|
+
* Does the same as `target = source`,
|
|
394
|
+
* except that it mutates the target to make it exactly the same as source,
|
|
395
|
+
* while keeping the reference to the same object.
|
|
396
|
+
*
|
|
397
|
+
* This way it can "propagate deletions".
|
|
398
|
+
* E.g source doesn't have the `n` property, so it'll be deleted from target.
|
|
399
|
+
* With normal Object.assign - it'll override the keys that `source` has, but not the
|
|
400
|
+
* "missing/deleted keys".
|
|
401
|
+
*
|
|
402
|
+
* To make mutation extra clear - function returns void (unlike Object.assign).
|
|
403
|
+
*/
|
|
404
|
+
function _objectAssignExact(target, source) {
|
|
405
|
+
Object.assign(target, source);
|
|
406
|
+
Object.keys(target)
|
|
407
|
+
.filter(k => !(k in source))
|
|
408
|
+
.forEach(k => delete target[k]);
|
|
409
|
+
}
|
|
410
|
+
exports._objectAssignExact = _objectAssignExact;
|
package/dist/types.d.ts
CHANGED
|
@@ -154,11 +154,12 @@ export type IsoDateString = string;
|
|
|
154
154
|
*/
|
|
155
155
|
export type IsoDateTimeString = string;
|
|
156
156
|
/**
|
|
157
|
+
* Identifies the Month.
|
|
157
158
|
* Like IsoDateString, but without the Day token.
|
|
158
159
|
*
|
|
159
160
|
* @example '2023-09'
|
|
160
161
|
*/
|
|
161
|
-
export type
|
|
162
|
+
export type MonthId = string;
|
|
162
163
|
/**
|
|
163
164
|
* Interface explicitly states that the value is a Unix timestamp (in seconds).
|
|
164
165
|
*
|
|
@@ -176,6 +176,16 @@ export class LocalDate {
|
|
|
176
176
|
return false;
|
|
177
177
|
return true;
|
|
178
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Checks if this localDate is older than "today" by X units.
|
|
181
|
+
*
|
|
182
|
+
* Example:
|
|
183
|
+
*
|
|
184
|
+
* localDate(expirationDate).isOlderThan(5, 'day')
|
|
185
|
+
*/
|
|
186
|
+
isOlderThan(n, unit) {
|
|
187
|
+
return this.isBefore(LocalDate.today().add(-n, unit));
|
|
188
|
+
}
|
|
179
189
|
/**
|
|
180
190
|
* Returns 1 if this > d
|
|
181
191
|
* returns 0 if they are equal
|
|
@@ -390,6 +400,9 @@ export class LocalDate {
|
|
|
390
400
|
String(this.$day).padStart(2, '0'),
|
|
391
401
|
].join('');
|
|
392
402
|
}
|
|
403
|
+
toMonthId() {
|
|
404
|
+
return this.toString().slice(0, 7);
|
|
405
|
+
}
|
|
393
406
|
// May be not optimal, as LocalTime better suits it
|
|
394
407
|
unix() {
|
|
395
408
|
return Math.floor(this.toDate().valueOf() / 1000);
|
|
@@ -355,6 +355,16 @@ export class LocalTime {
|
|
|
355
355
|
return false;
|
|
356
356
|
return true;
|
|
357
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* Checks if this localTime is older than "now" by X units.
|
|
360
|
+
*
|
|
361
|
+
* Example:
|
|
362
|
+
*
|
|
363
|
+
* localTime(expirationDate).isOlderThan(5, 'day')
|
|
364
|
+
*/
|
|
365
|
+
isOlderThan(n, unit) {
|
|
366
|
+
return this.isBefore(LocalTime.now().add(-n, unit));
|
|
367
|
+
}
|
|
358
368
|
/**
|
|
359
369
|
* Returns 1 if this > d
|
|
360
370
|
* returns 0 if they are equal
|
|
@@ -478,6 +488,9 @@ export class LocalTime {
|
|
|
478
488
|
toJSON() {
|
|
479
489
|
return this.unix();
|
|
480
490
|
}
|
|
491
|
+
toMonthId() {
|
|
492
|
+
return this.$date.toISOString().slice(0, 7);
|
|
493
|
+
}
|
|
481
494
|
format(fmt) {
|
|
482
495
|
if (fmt instanceof Intl.DateTimeFormat) {
|
|
483
496
|
return fmt.format(this.$date);
|
|
@@ -358,3 +358,26 @@ export function _deepFreeze(o) {
|
|
|
358
358
|
}
|
|
359
359
|
});
|
|
360
360
|
}
|
|
361
|
+
/**
|
|
362
|
+
* let target: T = { a: 'a', n: 1}
|
|
363
|
+
* let source: T = { a: 'a2', b: 'b' }
|
|
364
|
+
*
|
|
365
|
+
* _objectAssignExact(target, source)
|
|
366
|
+
*
|
|
367
|
+
* Does the same as `target = source`,
|
|
368
|
+
* except that it mutates the target to make it exactly the same as source,
|
|
369
|
+
* while keeping the reference to the same object.
|
|
370
|
+
*
|
|
371
|
+
* This way it can "propagate deletions".
|
|
372
|
+
* E.g source doesn't have the `n` property, so it'll be deleted from target.
|
|
373
|
+
* With normal Object.assign - it'll override the keys that `source` has, but not the
|
|
374
|
+
* "missing/deleted keys".
|
|
375
|
+
*
|
|
376
|
+
* To make mutation extra clear - function returns void (unlike Object.assign).
|
|
377
|
+
*/
|
|
378
|
+
export function _objectAssignExact(target, source) {
|
|
379
|
+
Object.assign(target, source);
|
|
380
|
+
Object.keys(target)
|
|
381
|
+
.filter(k => !(k in source))
|
|
382
|
+
.forEach(k => delete target[k]);
|
|
383
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.185.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"build-prod": "build-prod-esm-cjs",
|
|
7
|
-
"docs-
|
|
8
|
-
"docs-build": "
|
|
7
|
+
"docs-dev": "vitepress dev docs --open",
|
|
8
|
+
"docs-build": "vitepress build docs",
|
|
9
|
+
"docs-preview": "vitepress preview docs"
|
|
9
10
|
},
|
|
10
11
|
"dependencies": {
|
|
11
12
|
"tslib": "^2.0.0",
|
|
@@ -21,8 +22,8 @@
|
|
|
21
22
|
"crypto-js": "^4.1.1",
|
|
22
23
|
"jest": "^29.0.0",
|
|
23
24
|
"prettier": "^3.0.0",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
25
|
+
"vitepress": "^1.0.0-rc.12",
|
|
26
|
+
"vue": "^3.2.45"
|
|
26
27
|
},
|
|
27
28
|
"resolutions": {
|
|
28
29
|
"expect-type": "0.15.0"
|
|
@@ -2,6 +2,7 @@ import { _assert } from '../error/assert'
|
|
|
2
2
|
import type {
|
|
3
3
|
IsoDateString,
|
|
4
4
|
IsoDateTimeString,
|
|
5
|
+
MonthId,
|
|
5
6
|
UnixTimestampMillisNumber,
|
|
6
7
|
UnixTimestampNumber,
|
|
7
8
|
} from '../types'
|
|
@@ -239,6 +240,17 @@ export class LocalDate {
|
|
|
239
240
|
return true
|
|
240
241
|
}
|
|
241
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Checks if this localDate is older than "today" by X units.
|
|
245
|
+
*
|
|
246
|
+
* Example:
|
|
247
|
+
*
|
|
248
|
+
* localDate(expirationDate).isOlderThan(5, 'day')
|
|
249
|
+
*/
|
|
250
|
+
isOlderThan(n: number, unit: LocalDateUnitStrict): boolean {
|
|
251
|
+
return this.isBefore(LocalDate.today().add(-n, unit))
|
|
252
|
+
}
|
|
253
|
+
|
|
242
254
|
/**
|
|
243
255
|
* Returns 1 if this > d
|
|
244
256
|
* returns 0 if they are equal
|
|
@@ -482,6 +494,10 @@ export class LocalDate {
|
|
|
482
494
|
].join('')
|
|
483
495
|
}
|
|
484
496
|
|
|
497
|
+
toMonthId(): MonthId {
|
|
498
|
+
return this.toString().slice(0, 7)
|
|
499
|
+
}
|
|
500
|
+
|
|
485
501
|
// May be not optimal, as LocalTime better suits it
|
|
486
502
|
unix(): UnixTimestampNumber {
|
|
487
503
|
return Math.floor(this.toDate().valueOf() / 1000)
|
|
@@ -3,6 +3,7 @@ import { _ms } from '../time/time.util'
|
|
|
3
3
|
import type {
|
|
4
4
|
IsoDateString,
|
|
5
5
|
IsoDateTimeString,
|
|
6
|
+
MonthId,
|
|
6
7
|
UnixTimestampMillisNumber,
|
|
7
8
|
UnixTimestampNumber,
|
|
8
9
|
} from '../types'
|
|
@@ -439,6 +440,17 @@ export class LocalTime {
|
|
|
439
440
|
return true
|
|
440
441
|
}
|
|
441
442
|
|
|
443
|
+
/**
|
|
444
|
+
* Checks if this localTime is older than "now" by X units.
|
|
445
|
+
*
|
|
446
|
+
* Example:
|
|
447
|
+
*
|
|
448
|
+
* localTime(expirationDate).isOlderThan(5, 'day')
|
|
449
|
+
*/
|
|
450
|
+
isOlderThan(n: number, unit: LocalTimeUnit): boolean {
|
|
451
|
+
return this.isBefore(LocalTime.now().add(-n, unit))
|
|
452
|
+
}
|
|
453
|
+
|
|
442
454
|
/**
|
|
443
455
|
* Returns 1 if this > d
|
|
444
456
|
* returns 0 if they are equal
|
|
@@ -587,6 +599,10 @@ export class LocalTime {
|
|
|
587
599
|
return this.unix()
|
|
588
600
|
}
|
|
589
601
|
|
|
602
|
+
toMonthId(): MonthId {
|
|
603
|
+
return this.$date.toISOString().slice(0, 7)
|
|
604
|
+
}
|
|
605
|
+
|
|
590
606
|
format(fmt: Intl.DateTimeFormat | LocalTimeFormatter): string {
|
|
591
607
|
if (fmt instanceof Intl.DateTimeFormat) {
|
|
592
608
|
return fmt.format(this.$date)
|
|
@@ -419,3 +419,27 @@ export function _deepFreeze(o: any): void {
|
|
|
419
419
|
}
|
|
420
420
|
})
|
|
421
421
|
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* let target: T = { a: 'a', n: 1}
|
|
425
|
+
* let source: T = { a: 'a2', b: 'b' }
|
|
426
|
+
*
|
|
427
|
+
* _objectAssignExact(target, source)
|
|
428
|
+
*
|
|
429
|
+
* Does the same as `target = source`,
|
|
430
|
+
* except that it mutates the target to make it exactly the same as source,
|
|
431
|
+
* while keeping the reference to the same object.
|
|
432
|
+
*
|
|
433
|
+
* This way it can "propagate deletions".
|
|
434
|
+
* E.g source doesn't have the `n` property, so it'll be deleted from target.
|
|
435
|
+
* With normal Object.assign - it'll override the keys that `source` has, but not the
|
|
436
|
+
* "missing/deleted keys".
|
|
437
|
+
*
|
|
438
|
+
* To make mutation extra clear - function returns void (unlike Object.assign).
|
|
439
|
+
*/
|
|
440
|
+
export function _objectAssignExact<T extends AnyObject>(target: T, source: T): void {
|
|
441
|
+
Object.assign(target, source)
|
|
442
|
+
Object.keys(target)
|
|
443
|
+
.filter(k => !(k in source))
|
|
444
|
+
.forEach(k => delete target[k])
|
|
445
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -215,11 +215,12 @@ export type IsoDateString = string
|
|
|
215
215
|
export type IsoDateTimeString = string
|
|
216
216
|
|
|
217
217
|
/**
|
|
218
|
+
* Identifies the Month.
|
|
218
219
|
* Like IsoDateString, but without the Day token.
|
|
219
220
|
*
|
|
220
221
|
* @example '2023-09'
|
|
221
222
|
*/
|
|
222
|
-
export type
|
|
223
|
+
export type MonthId = string
|
|
223
224
|
|
|
224
225
|
/**
|
|
225
226
|
* Interface explicitly states that the value is a Unix timestamp (in seconds).
|