@naturalcycles/js-lib 14.247.1 → 14.248.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/define.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyFunction, AnyObject } from './types';
1
+ import type { AnyFunction, AnyObject, Lazy } from './types';
2
2
  /**
3
3
  * const value = lazyValue(() => expensiveComputation())
4
4
  *
@@ -8,7 +8,7 @@ import type { AnyFunction, AnyObject } from './types';
8
8
  *
9
9
  * Based on: https://github.com/sindresorhus/lazy-value
10
10
  */
11
- export declare function _lazyValue<T extends AnyFunction>(fn: T): T;
11
+ export declare function _lazyValue<T>(fn: () => T): Lazy<T>;
12
12
  /**
13
13
  * interface Obj {
14
14
  * v: number
package/dist/types.d.ts CHANGED
@@ -71,6 +71,18 @@ export type AnyAsyncFunction<T = any> = (...args: any[]) => Promise<T>;
71
71
  export type AsyncFunction<T = any> = () => Promise<T>;
72
72
  export type AnyPromisableFunction<T = any> = (...args: any[]) => Promisable<T>;
73
73
  export type PromisableFunction<T = any> = () => Promisable<T>;
74
+ /**
75
+ * A function that lazily calculates something.
76
+ */
77
+ export type Lazy<T> = () => T;
78
+ /**
79
+ * A function that lazily calculates something async (returns a Promise).
80
+ */
81
+ export type LazyPromise<T> = () => Promise<T>;
82
+ /**
83
+ * A function that lazily calculates something async, that can return null.
84
+ */
85
+ export type LazyNullablePromise<T> = () => Promise<T | null>;
74
86
  /**
75
87
  * Symbol to indicate END of Sequence.
76
88
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.247.1",
3
+ "version": "14.248.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build-esm-cjs",
package/src/define.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { _mapObject, _mapValues } from './object/object.util'
2
- import type { AnyFunction, AnyObject } from './types'
2
+ import type { AnyFunction, AnyObject, Lazy } from './types'
3
3
  import { SKIP } from './types'
4
4
 
5
5
  /**
@@ -11,7 +11,7 @@ import { SKIP } from './types'
11
11
  *
12
12
  * Based on: https://github.com/sindresorhus/lazy-value
13
13
  */
14
- export function _lazyValue<T extends AnyFunction>(fn: T): T {
14
+ export function _lazyValue<T>(fn: () => T): Lazy<T> {
15
15
  let isCalled = false
16
16
  let result: any
17
17
 
package/src/types.ts CHANGED
@@ -90,6 +90,18 @@ export type AnyAsyncFunction<T = any> = (...args: any[]) => Promise<T>
90
90
  export type AsyncFunction<T = any> = () => Promise<T>
91
91
  export type AnyPromisableFunction<T = any> = (...args: any[]) => Promisable<T>
92
92
  export type PromisableFunction<T = any> = () => Promisable<T>
93
+ /**
94
+ * A function that lazily calculates something.
95
+ */
96
+ export type Lazy<T> = () => T
97
+ /**
98
+ * A function that lazily calculates something async (returns a Promise).
99
+ */
100
+ export type LazyPromise<T> = () => Promise<T>
101
+ /**
102
+ * A function that lazily calculates something async, that can return null.
103
+ */
104
+ export type LazyNullablePromise<T> = () => Promise<T | null>
93
105
 
94
106
  /**
95
107
  * Symbol to indicate END of Sequence.