@naturalcycles/js-lib 14.180.0 → 14.181.1

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.
@@ -96,4 +96,10 @@ export declare class LocalDate {
96
96
  /**
97
97
  * Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
98
98
  */
99
- export declare function localDate(d?: LocalDateInput): LocalDate;
99
+ export declare function localDate(d?: LocalDateInput | null): LocalDate;
100
+ /**
101
+ * Creates a LocalDate from the input, unless it's falsy - then returns undefined.
102
+ *
103
+ * `localDate` function will instead return LocalDate of today for falsy input.
104
+ */
105
+ export declare function localDateOrUndefined(d?: LocalDateInput | null): LocalDate | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.localDate = exports.LocalDate = void 0;
3
+ exports.localDateOrUndefined = 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];
@@ -418,3 +418,12 @@ function localDate(d) {
418
418
  return d ? LocalDate.of(d) : LocalDate.today();
419
419
  }
420
420
  exports.localDate = localDate;
421
+ /**
422
+ * Creates a LocalDate from the input, unless it's falsy - then returns undefined.
423
+ *
424
+ * `localDate` function will instead return LocalDate of today for falsy input.
425
+ */
426
+ function localDateOrUndefined(d) {
427
+ return d ? LocalDate.of(d) : undefined;
428
+ }
429
+ exports.localDateOrUndefined = localDateOrUndefined;
@@ -125,4 +125,10 @@ export declare class LocalTime {
125
125
  /**
126
126
  * Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
127
127
  */
128
- export declare function localTime(d?: LocalTimeInput): LocalTime;
128
+ export declare function localTime(d?: LocalTimeInput | null): LocalTime;
129
+ /**
130
+ * Creates a LocalTime from the input, unless it's falsy - then returns undefined.
131
+ *
132
+ * `localTime` function will instead return LocalTime of `now` for falsy input.
133
+ */
134
+ export declare function localTimeOrUndefined(d?: LocalTimeInput | null): LocalTime | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.localTime = exports.LocalTime = exports.ISODayOfWeek = void 0;
3
+ exports.localTimeOrUndefined = 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");
@@ -495,6 +495,15 @@ function localTime(d) {
495
495
  return d ? LocalTime.of(d) : LocalTime.now();
496
496
  }
497
497
  exports.localTime = localTime;
498
+ /**
499
+ * Creates a LocalTime from the input, unless it's falsy - then returns undefined.
500
+ *
501
+ * `localTime` function will instead return LocalTime of `now` for falsy input.
502
+ */
503
+ function localTimeOrUndefined(d) {
504
+ return d ? LocalTime.of(d) : undefined;
505
+ }
506
+ exports.localTimeOrUndefined = localTimeOrUndefined;
498
507
  // based on: https://github.com/date-fns/date-fns/blob/master/src/getISOWeek/index.ts
499
508
  function getWeek(date) {
500
509
  const diff = startOfWeek(date).getTime() - startOfWeekYear(date).getTime();
@@ -413,3 +413,11 @@ export class LocalDate {
413
413
  export function localDate(d) {
414
414
  return d ? LocalDate.of(d) : LocalDate.today();
415
415
  }
416
+ /**
417
+ * Creates a LocalDate from the input, unless it's falsy - then returns undefined.
418
+ *
419
+ * `localDate` function will instead return LocalDate of today for falsy input.
420
+ */
421
+ export function localDateOrUndefined(d) {
422
+ return d ? LocalDate.of(d) : undefined;
423
+ }
@@ -491,6 +491,14 @@ export class LocalTime {
491
491
  export function localTime(d) {
492
492
  return d ? LocalTime.of(d) : LocalTime.now();
493
493
  }
494
+ /**
495
+ * Creates a LocalTime from the input, unless it's falsy - then returns undefined.
496
+ *
497
+ * `localTime` function will instead return LocalTime of `now` for falsy input.
498
+ */
499
+ export function localTimeOrUndefined(d) {
500
+ return d ? LocalTime.of(d) : undefined;
501
+ }
494
502
  // based on: https://github.com/date-fns/date-fns/blob/master/src/getISOWeek/index.ts
495
503
  function getWeek(date) {
496
504
  const diff = startOfWeek(date).getTime() - startOfWeekYear(date).getTime();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.180.0",
3
+ "version": "14.181.1",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -507,6 +507,15 @@ export class LocalDate {
507
507
  /**
508
508
  * Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
509
509
  */
510
- export function localDate(d?: LocalDateInput): LocalDate {
510
+ export function localDate(d?: LocalDateInput | null): LocalDate {
511
511
  return d ? LocalDate.of(d) : LocalDate.today()
512
512
  }
513
+
514
+ /**
515
+ * Creates a LocalDate from the input, unless it's falsy - then returns undefined.
516
+ *
517
+ * `localDate` function will instead return LocalDate of today for falsy input.
518
+ */
519
+ export function localDateOrUndefined(d?: LocalDateInput | null): LocalDate | undefined {
520
+ return d ? LocalDate.of(d) : undefined
521
+ }
@@ -599,10 +599,19 @@ export class LocalTime {
599
599
  /**
600
600
  * Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
601
601
  */
602
- export function localTime(d?: LocalTimeInput): LocalTime {
602
+ export function localTime(d?: LocalTimeInput | null): LocalTime {
603
603
  return d ? LocalTime.of(d) : LocalTime.now()
604
604
  }
605
605
 
606
+ /**
607
+ * Creates a LocalTime from the input, unless it's falsy - then returns undefined.
608
+ *
609
+ * `localTime` function will instead return LocalTime of `now` for falsy input.
610
+ */
611
+ export function localTimeOrUndefined(d?: LocalTimeInput | null): LocalTime | undefined {
612
+ return d ? LocalTime.of(d) : undefined
613
+ }
614
+
606
615
  // based on: https://github.com/date-fns/date-fns/blob/master/src/getISOWeek/index.ts
607
616
  function getWeek(date: Date): number {
608
617
  const diff = startOfWeek(date).getTime() - startOfWeekYear(date).getTime()