@naturalcycles/js-lib 14.179.0 → 14.181.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.
@@ -97,3 +97,9 @@ export declare class LocalDate {
97
97
  * Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
98
98
  */
99
99
  export declare function localDate(d?: LocalDateInput): 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): 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;
@@ -126,3 +126,9 @@ export declare class LocalTime {
126
126
  * Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
127
127
  */
128
128
  export declare function localTime(d?: LocalTimeInput): 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): 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();
package/dist/index.d.ts CHANGED
@@ -80,6 +80,7 @@ export * from './env/buildInfo';
80
80
  export * from './form.util';
81
81
  export * from './semver';
82
82
  export * from './web';
83
+ export * from './polyfill';
83
84
  export * from './zod/zod.util';
84
85
  export * from './zod/zod.shared.schemas';
85
86
  import { z, ZodSchema, ZodError, ZodIssue } from 'zod';
package/dist/index.js CHANGED
@@ -84,6 +84,7 @@ tslib_1.__exportStar(require("./env/buildInfo"), exports);
84
84
  tslib_1.__exportStar(require("./form.util"), exports);
85
85
  tslib_1.__exportStar(require("./semver"), exports);
86
86
  tslib_1.__exportStar(require("./web"), exports);
87
+ tslib_1.__exportStar(require("./polyfill"), exports);
87
88
  tslib_1.__exportStar(require("./zod/zod.util"), exports);
88
89
  tslib_1.__exportStar(require("./zod/zod.shared.schemas"), exports);
89
90
  const zod_1 = require("zod");
@@ -0,0 +1 @@
1
+ export declare function polyfillDispose(): void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.polyfillDispose = void 0;
4
+ function polyfillDispose() {
5
+ // @ts-expect-error polyfill
6
+ Symbol.dispose ??= Symbol('Symbol.dispose');
7
+ // @ts-expect-error polyfill
8
+ Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose');
9
+ }
10
+ exports.polyfillDispose = polyfillDispose;
@@ -1,3 +1,13 @@
1
+ /**
2
+ * using _ = blockTimer()
3
+ * // will log "took 1.234 sec" on dispose
4
+ *
5
+ * using _ = blockTimer('named')
6
+ * // will log "named took 1.234 sec" on dispose
7
+ *
8
+ * @experimental
9
+ */
10
+ export declare function _blockTimer(name?: string): Disposable;
1
11
  /**
2
12
  * Returns time passed since `from` until `until` (default to Date.now())
3
13
  */
@@ -1,6 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._ms = exports._since = void 0;
3
+ exports._ms = exports._since = exports._blockTimer = void 0;
4
+ /**
5
+ * using _ = blockTimer()
6
+ * // will log "took 1.234 sec" on dispose
7
+ *
8
+ * using _ = blockTimer('named')
9
+ * // will log "named took 1.234 sec" on dispose
10
+ *
11
+ * @experimental
12
+ */
13
+ function _blockTimer(name) {
14
+ const started = Date.now();
15
+ return {
16
+ [Symbol.dispose]() {
17
+ console.log(`${name ? name + ' ' : ''}took ${_since(started)}`);
18
+ },
19
+ };
20
+ }
21
+ exports._blockTimer = _blockTimer;
4
22
  /**
5
23
  * Returns time passed since `from` until `until` (default to Date.now())
6
24
  */
@@ -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/dist-esm/index.js CHANGED
@@ -80,6 +80,7 @@ export * from './env/buildInfo';
80
80
  export * from './form.util';
81
81
  export * from './semver';
82
82
  export * from './web';
83
+ export * from './polyfill';
83
84
  export * from './zod/zod.util';
84
85
  export * from './zod/zod.shared.schemas';
85
86
  import { z, ZodSchema, ZodError } from 'zod';
@@ -0,0 +1,7 @@
1
+ export function polyfillDispose() {
2
+ var _a, _b;
3
+ // @ts-expect-error polyfill
4
+ (_a = Symbol.dispose) !== null && _a !== void 0 ? _a : (Symbol.dispose = Symbol('Symbol.dispose'));
5
+ // @ts-expect-error polyfill
6
+ (_b = Symbol.asyncDispose) !== null && _b !== void 0 ? _b : (Symbol.asyncDispose = Symbol('Symbol.asyncDispose'));
7
+ }
@@ -1,3 +1,20 @@
1
+ /**
2
+ * using _ = blockTimer()
3
+ * // will log "took 1.234 sec" on dispose
4
+ *
5
+ * using _ = blockTimer('named')
6
+ * // will log "named took 1.234 sec" on dispose
7
+ *
8
+ * @experimental
9
+ */
10
+ export function _blockTimer(name) {
11
+ const started = Date.now();
12
+ return {
13
+ [Symbol.dispose]() {
14
+ console.log(`${name ? name + ' ' : ''}took ${_since(started)}`);
15
+ },
16
+ };
17
+ }
1
18
  /**
2
19
  * Returns time passed since `from` until `until` (default to Date.now())
3
20
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.179.0",
3
+ "version": "14.181.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -510,3 +510,12 @@ export class LocalDate {
510
510
  export function localDate(d?: LocalDateInput): 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): LocalDate | undefined {
520
+ return d ? LocalDate.of(d) : undefined
521
+ }
@@ -603,6 +603,15 @@ export function localTime(d?: LocalTimeInput): 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): 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()
package/src/index.ts CHANGED
@@ -80,6 +80,7 @@ export * from './env/buildInfo'
80
80
  export * from './form.util'
81
81
  export * from './semver'
82
82
  export * from './web'
83
+ export * from './polyfill'
83
84
  export * from './zod/zod.util'
84
85
  export * from './zod/zod.shared.schemas'
85
86
  import { z, ZodSchema, ZodError, ZodIssue } from 'zod'
@@ -0,0 +1,6 @@
1
+ export function polyfillDispose(): void {
2
+ // @ts-expect-error polyfill
3
+ Symbol.dispose ??= Symbol('Symbol.dispose')
4
+ // @ts-expect-error polyfill
5
+ Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose')
6
+ }
@@ -1,3 +1,21 @@
1
+ /**
2
+ * using _ = blockTimer()
3
+ * // will log "took 1.234 sec" on dispose
4
+ *
5
+ * using _ = blockTimer('named')
6
+ * // will log "named took 1.234 sec" on dispose
7
+ *
8
+ * @experimental
9
+ */
10
+ export function _blockTimer(name?: string): Disposable {
11
+ const started = Date.now()
12
+ return {
13
+ [Symbol.dispose](): void {
14
+ console.log(`${name ? name + ' ' : ''}took ${_since(started)}`)
15
+ },
16
+ } as any
17
+ }
18
+
1
19
  /**
2
20
  * Returns time passed since `from` until `until` (default to Date.now())
3
21
  */