@naturalcycles/js-lib 14.182.0 → 14.183.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.
@@ -15,7 +15,7 @@ export declare class LocalDate {
15
15
  private constructor();
16
16
  static create(year: number, month: number, day: number): LocalDate;
17
17
  /**
18
- * Parses input String into LocalDate.
18
+ * Parses input into LocalDate.
19
19
  * Input can already be a LocalDate - it is returned as-is in that case.
20
20
  */
21
21
  static of(d: LocalDateInput): LocalDate;
@@ -94,9 +94,12 @@ export declare class LocalDate {
94
94
  format(fmt: Intl.DateTimeFormat | LocalDateFormatter): string;
95
95
  }
96
96
  /**
97
- * Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
97
+ * Convenience wrapper around `LocalDate.of`
98
+ */
99
+ export declare function localDate(d: LocalDateInput): LocalDate;
100
+ /**
101
+ * Convenience wrapper around `LocalDate.today`
98
102
  */
99
- export declare function localDate(d?: LocalDateInput | null): LocalDate;
100
103
  export declare function localDateToday(): LocalDate;
101
104
  /**
102
105
  * Creates a LocalDate from the input, unless it's falsy - then returns undefined.
@@ -104,3 +107,7 @@ export declare function localDateToday(): LocalDate;
104
107
  * `localDate` function will instead return LocalDate of today for falsy input.
105
108
  */
106
109
  export declare function localDateOrUndefined(d?: LocalDateInput | null): LocalDate | undefined;
110
+ /**
111
+ * Creates a LocalDate from the input, unless it's falsy - then returns LocalDate.today.
112
+ */
113
+ export declare function localDateOrToday(d?: LocalDateInput | null): LocalDate;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.localDateOrUndefined = exports.localDateToday = exports.localDate = exports.LocalDate = void 0;
3
+ exports.localDateOrToday = exports.localDateOrUndefined = exports.localDateToday = exports.localDate = exports.LocalDate = void 0;
4
4
  const assert_1 = require("../error/assert");
5
5
  const localTime_1 = require("./localTime");
6
6
  const MDAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
@@ -18,7 +18,7 @@ class LocalDate {
18
18
  return new LocalDate(year, month, day);
19
19
  }
20
20
  /**
21
- * Parses input String into LocalDate.
21
+ * Parses input into LocalDate.
22
22
  * Input can already be a LocalDate - it is returned as-is in that case.
23
23
  */
24
24
  static of(d) {
@@ -412,12 +412,15 @@ class LocalDate {
412
412
  }
413
413
  exports.LocalDate = LocalDate;
414
414
  /**
415
- * Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
415
+ * Convenience wrapper around `LocalDate.of`
416
416
  */
417
417
  function localDate(d) {
418
- return d ? LocalDate.of(d) : LocalDate.today();
418
+ return LocalDate.of(d);
419
419
  }
420
420
  exports.localDate = localDate;
421
+ /**
422
+ * Convenience wrapper around `LocalDate.today`
423
+ */
421
424
  function localDateToday() {
422
425
  return LocalDate.today();
423
426
  }
@@ -431,3 +434,10 @@ function localDateOrUndefined(d) {
431
434
  return d ? LocalDate.of(d) : undefined;
432
435
  }
433
436
  exports.localDateOrUndefined = localDateOrUndefined;
437
+ /**
438
+ * Creates a LocalDate from the input, unless it's falsy - then returns LocalDate.today.
439
+ */
440
+ function localDateOrToday(d) {
441
+ return d ? LocalDate.of(d) : LocalDate.today();
442
+ }
443
+ exports.localDateOrToday = localDateOrToday;
@@ -123,9 +123,12 @@ export declare class LocalTime {
123
123
  format(fmt: Intl.DateTimeFormat | LocalTimeFormatter): string;
124
124
  }
125
125
  /**
126
- * Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
126
+ * Shortcut wrapper around `LocalTime.of`
127
+ */
128
+ export declare function localTime(d: LocalTimeInput): LocalTime;
129
+ /**
130
+ * Shortcut wrapper around `LocalTime.now`
127
131
  */
128
- export declare function localTime(d?: LocalTimeInput | null): LocalTime;
129
132
  export declare function localTimeNow(): LocalTime;
130
133
  /**
131
134
  * Creates a LocalTime from the input, unless it's falsy - then returns undefined.
@@ -133,3 +136,7 @@ export declare function localTimeNow(): LocalTime;
133
136
  * `localTime` function will instead return LocalTime of `now` for falsy input.
134
137
  */
135
138
  export declare function localTimeOrUndefined(d?: LocalTimeInput | null): LocalTime | undefined;
139
+ /**
140
+ * Creates a LocalTime from the input, unless it's falsy - then returns LocalTime.now
141
+ */
142
+ export declare function localTimeOrNow(d?: LocalTimeInput | null): LocalTime;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.localTimeOrUndefined = exports.localTimeNow = exports.localTime = exports.LocalTime = exports.ISODayOfWeek = void 0;
3
+ exports.localTimeOrNow = exports.localTimeOrUndefined = exports.localTimeNow = exports.localTime = exports.LocalTime = exports.ISODayOfWeek = void 0;
4
4
  const assert_1 = require("../error/assert");
5
5
  const time_util_1 = require("../time/time.util");
6
6
  const localDate_1 = require("./localDate");
@@ -489,12 +489,15 @@ class LocalTime {
489
489
  }
490
490
  exports.LocalTime = LocalTime;
491
491
  /**
492
- * Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
492
+ * Shortcut wrapper around `LocalTime.of`
493
493
  */
494
494
  function localTime(d) {
495
- return d ? LocalTime.of(d) : LocalTime.now();
495
+ return LocalTime.of(d);
496
496
  }
497
497
  exports.localTime = localTime;
498
+ /**
499
+ * Shortcut wrapper around `LocalTime.now`
500
+ */
498
501
  function localTimeNow() {
499
502
  return LocalTime.now();
500
503
  }
@@ -508,6 +511,13 @@ function localTimeOrUndefined(d) {
508
511
  return d ? LocalTime.of(d) : undefined;
509
512
  }
510
513
  exports.localTimeOrUndefined = localTimeOrUndefined;
514
+ /**
515
+ * Creates a LocalTime from the input, unless it's falsy - then returns LocalTime.now
516
+ */
517
+ function localTimeOrNow(d) {
518
+ return d ? LocalTime.of(d) : LocalTime.now();
519
+ }
520
+ exports.localTimeOrNow = localTimeOrNow;
511
521
  // based on: https://github.com/date-fns/date-fns/blob/master/src/getISOWeek/index.ts
512
522
  function getWeek(date) {
513
523
  const diff = startOfWeek(date).getTime() - startOfWeekYear(date).getTime();
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateBuildInfoDev = void 0;
4
4
  const localTime_1 = require("../datetime/localTime");
5
5
  function generateBuildInfoDev() {
6
- const now = (0, localTime_1.localTime)();
6
+ const now = (0, localTime_1.localTimeNow)();
7
7
  const ts = now.unix();
8
8
  const rev = 'devRev';
9
9
  const branchName = 'devBranch';
@@ -15,7 +15,7 @@ export class LocalDate {
15
15
  return new LocalDate(year, month, day);
16
16
  }
17
17
  /**
18
- * Parses input String into LocalDate.
18
+ * Parses input into LocalDate.
19
19
  * Input can already be a LocalDate - it is returned as-is in that case.
20
20
  */
21
21
  static of(d) {
@@ -408,11 +408,14 @@ export class LocalDate {
408
408
  }
409
409
  }
410
410
  /**
411
- * Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
411
+ * Convenience wrapper around `LocalDate.of`
412
412
  */
413
413
  export function localDate(d) {
414
- return d ? LocalDate.of(d) : LocalDate.today();
414
+ return LocalDate.of(d);
415
415
  }
416
+ /**
417
+ * Convenience wrapper around `LocalDate.today`
418
+ */
416
419
  export function localDateToday() {
417
420
  return LocalDate.today();
418
421
  }
@@ -424,3 +427,9 @@ export function localDateToday() {
424
427
  export function localDateOrUndefined(d) {
425
428
  return d ? LocalDate.of(d) : undefined;
426
429
  }
430
+ /**
431
+ * Creates a LocalDate from the input, unless it's falsy - then returns LocalDate.today.
432
+ */
433
+ export function localDateOrToday(d) {
434
+ return d ? LocalDate.of(d) : LocalDate.today();
435
+ }
@@ -486,11 +486,14 @@ export class LocalTime {
486
486
  }
487
487
  }
488
488
  /**
489
- * Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
489
+ * Shortcut wrapper around `LocalTime.of`
490
490
  */
491
491
  export function localTime(d) {
492
- return d ? LocalTime.of(d) : LocalTime.now();
492
+ return LocalTime.of(d);
493
493
  }
494
+ /**
495
+ * Shortcut wrapper around `LocalTime.now`
496
+ */
494
497
  export function localTimeNow() {
495
498
  return LocalTime.now();
496
499
  }
@@ -502,6 +505,12 @@ export function localTimeNow() {
502
505
  export function localTimeOrUndefined(d) {
503
506
  return d ? LocalTime.of(d) : undefined;
504
507
  }
508
+ /**
509
+ * Creates a LocalTime from the input, unless it's falsy - then returns LocalTime.now
510
+ */
511
+ export function localTimeOrNow(d) {
512
+ return d ? LocalTime.of(d) : LocalTime.now();
513
+ }
505
514
  // based on: https://github.com/date-fns/date-fns/blob/master/src/getISOWeek/index.ts
506
515
  function getWeek(date) {
507
516
  const diff = startOfWeek(date).getTime() - startOfWeekYear(date).getTime();
@@ -1,6 +1,6 @@
1
- import { localTime } from '../datetime/localTime';
1
+ import { localTimeNow } from '../datetime/localTime';
2
2
  export function generateBuildInfoDev() {
3
- const now = localTime();
3
+ const now = localTimeNow();
4
4
  const ts = now.unix();
5
5
  const rev = 'devRev';
6
6
  const branchName = 'devBranch';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.182.0",
3
+ "version": "14.183.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -32,7 +32,7 @@ export class LocalDate {
32
32
  }
33
33
 
34
34
  /**
35
- * Parses input String into LocalDate.
35
+ * Parses input into LocalDate.
36
36
  * Input can already be a LocalDate - it is returned as-is in that case.
37
37
  */
38
38
  static of(d: LocalDateInput): LocalDate {
@@ -505,12 +505,15 @@ export class LocalDate {
505
505
  }
506
506
 
507
507
  /**
508
- * Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
508
+ * Convenience wrapper around `LocalDate.of`
509
509
  */
510
- export function localDate(d?: LocalDateInput | null): LocalDate {
511
- return d ? LocalDate.of(d) : LocalDate.today()
510
+ export function localDate(d: LocalDateInput): LocalDate {
511
+ return LocalDate.of(d)
512
512
  }
513
513
 
514
+ /**
515
+ * Convenience wrapper around `LocalDate.today`
516
+ */
514
517
  export function localDateToday(): LocalDate {
515
518
  return LocalDate.today()
516
519
  }
@@ -523,3 +526,10 @@ export function localDateToday(): LocalDate {
523
526
  export function localDateOrUndefined(d?: LocalDateInput | null): LocalDate | undefined {
524
527
  return d ? LocalDate.of(d) : undefined
525
528
  }
529
+
530
+ /**
531
+ * Creates a LocalDate from the input, unless it's falsy - then returns LocalDate.today.
532
+ */
533
+ export function localDateOrToday(d?: LocalDateInput | null): LocalDate {
534
+ return d ? LocalDate.of(d) : LocalDate.today()
535
+ }
@@ -597,12 +597,15 @@ export class LocalTime {
597
597
  }
598
598
 
599
599
  /**
600
- * Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
600
+ * Shortcut wrapper around `LocalTime.of`
601
601
  */
602
- export function localTime(d?: LocalTimeInput | null): LocalTime {
603
- return d ? LocalTime.of(d) : LocalTime.now()
602
+ export function localTime(d: LocalTimeInput): LocalTime {
603
+ return LocalTime.of(d)
604
604
  }
605
605
 
606
+ /**
607
+ * Shortcut wrapper around `LocalTime.now`
608
+ */
606
609
  export function localTimeNow(): LocalTime {
607
610
  return LocalTime.now()
608
611
  }
@@ -616,6 +619,13 @@ export function localTimeOrUndefined(d?: LocalTimeInput | null): LocalTime | und
616
619
  return d ? LocalTime.of(d) : undefined
617
620
  }
618
621
 
622
+ /**
623
+ * Creates a LocalTime from the input, unless it's falsy - then returns LocalTime.now
624
+ */
625
+ export function localTimeOrNow(d?: LocalTimeInput | null): LocalTime {
626
+ return d ? LocalTime.of(d) : LocalTime.now()
627
+ }
628
+
619
629
  // based on: https://github.com/date-fns/date-fns/blob/master/src/getISOWeek/index.ts
620
630
  function getWeek(date: Date): number {
621
631
  const diff = startOfWeek(date).getTime() - startOfWeekYear(date).getTime()
@@ -1,4 +1,4 @@
1
- import { localTime } from '../datetime/localTime'
1
+ import { localTimeNow } from '../datetime/localTime'
2
2
  import type { UnixTimestampNumber } from '../types'
3
3
 
4
4
  export interface BuildInfo {
@@ -43,7 +43,7 @@ export interface BuildInfo {
43
43
  }
44
44
 
45
45
  export function generateBuildInfoDev(): BuildInfo {
46
- const now = localTime()
46
+ const now = localTimeNow()
47
47
  const ts = now.unix()
48
48
  const rev = 'devRev'
49
49
  const branchName = 'devBranch'