@naturalcycles/js-lib 14.184.1 → 14.186.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.
@@ -55,8 +55,10 @@ export declare class LocalDate {
55
55
  * Example:
56
56
  *
57
57
  * localDate(expirationDate).isOlderThan(5, 'day')
58
+ *
59
+ * Third argument allows to override "today".
58
60
  */
59
- isOlderThan(n: number, unit: LocalDateUnitStrict): boolean;
61
+ isOlderThan(n: number, unit: LocalDateUnitStrict, today?: LocalDateInput): boolean;
60
62
  /**
61
63
  * Returns 1 if this > d
62
64
  * returns 0 if they are equal
@@ -185,9 +185,11 @@ class LocalDate {
185
185
  * Example:
186
186
  *
187
187
  * localDate(expirationDate).isOlderThan(5, 'day')
188
+ *
189
+ * Third argument allows to override "today".
188
190
  */
189
- isOlderThan(n, unit) {
190
- return this.isBefore(LocalDate.today().add(-n, unit));
191
+ isOlderThan(n, unit, today) {
192
+ return this.isBefore(LocalDate.of(today || new Date()).add(-n, unit));
191
193
  }
192
194
  /**
193
195
  * Returns 1 if this > d
@@ -93,8 +93,10 @@ export declare class LocalTime {
93
93
  * Example:
94
94
  *
95
95
  * localTime(expirationDate).isOlderThan(5, 'day')
96
+ *
97
+ * Third argument allows to override "now".
96
98
  */
97
- isOlderThan(n: number, unit: LocalTimeUnit): boolean;
99
+ isOlderThan(n: number, unit: LocalTimeUnit, now?: LocalTimeInput): boolean;
98
100
  /**
99
101
  * Returns 1 if this > d
100
102
  * returns 0 if they are equal
@@ -363,9 +363,11 @@ class LocalTime {
363
363
  * Example:
364
364
  *
365
365
  * localTime(expirationDate).isOlderThan(5, 'day')
366
+ *
367
+ * Third argument allows to override "now".
366
368
  */
367
- isOlderThan(n, unit) {
368
- return this.isBefore(LocalTime.now().add(-n, unit));
369
+ isOlderThan(n, unit, now) {
370
+ return this.isBefore(LocalTime.of(now ?? new Date()).add(-n, unit));
369
371
  }
370
372
  /**
371
373
  * Returns 1 if this > d
@@ -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;
@@ -182,9 +182,11 @@ export class LocalDate {
182
182
  * Example:
183
183
  *
184
184
  * localDate(expirationDate).isOlderThan(5, 'day')
185
+ *
186
+ * Third argument allows to override "today".
185
187
  */
186
- isOlderThan(n, unit) {
187
- return this.isBefore(LocalDate.today().add(-n, unit));
188
+ isOlderThan(n, unit, today) {
189
+ return this.isBefore(LocalDate.of(today || new Date()).add(-n, unit));
188
190
  }
189
191
  /**
190
192
  * Returns 1 if this > d
@@ -361,9 +361,11 @@ export class LocalTime {
361
361
  * Example:
362
362
  *
363
363
  * localTime(expirationDate).isOlderThan(5, 'day')
364
+ *
365
+ * Third argument allows to override "now".
364
366
  */
365
- isOlderThan(n, unit) {
366
- return this.isBefore(LocalTime.now().add(-n, unit));
367
+ isOlderThan(n, unit, now) {
368
+ return this.isBefore(LocalTime.of(now !== null && now !== void 0 ? now : new Date()).add(-n, unit));
367
369
  }
368
370
  /**
369
371
  * Returns 1 if this > d
@@ -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.184.1",
3
+ "version": "14.186.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
7
- "docs-serve": "NODE_OPTIONS=--openssl-legacy-provider vuepress dev docs",
8
- "docs-build": "NODE_OPTIONS=--openssl-legacy-provider vuepress build docs"
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
- "vuepress": "^1.7.1",
25
- "vuepress-plugin-typescript": "^0.3.1"
25
+ "vitepress": "^1.0.0-rc.12",
26
+ "vue": "^3.2.45"
26
27
  },
27
28
  "resolutions": {
28
29
  "expect-type": "0.15.0"
@@ -246,9 +246,11 @@ export class LocalDate {
246
246
  * Example:
247
247
  *
248
248
  * localDate(expirationDate).isOlderThan(5, 'day')
249
+ *
250
+ * Third argument allows to override "today".
249
251
  */
250
- isOlderThan(n: number, unit: LocalDateUnitStrict): boolean {
251
- return this.isBefore(LocalDate.today().add(-n, unit))
252
+ isOlderThan(n: number, unit: LocalDateUnitStrict, today?: LocalDateInput): boolean {
253
+ return this.isBefore(LocalDate.of(today || new Date()).add(-n, unit))
252
254
  }
253
255
 
254
256
  /**
@@ -446,9 +446,11 @@ export class LocalTime {
446
446
  * Example:
447
447
  *
448
448
  * localTime(expirationDate).isOlderThan(5, 'day')
449
+ *
450
+ * Third argument allows to override "now".
449
451
  */
450
- isOlderThan(n: number, unit: LocalTimeUnit): boolean {
451
- return this.isBefore(LocalTime.now().add(-n, unit))
452
+ isOlderThan(n: number, unit: LocalTimeUnit, now?: LocalTimeInput): boolean {
453
+ return this.isBefore(LocalTime.of(now ?? new Date()).add(-n, unit))
452
454
  }
453
455
 
454
456
  /**
@@ -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
+ }