@rimbu/common 0.8.0 → 0.8.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.
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AsyncOptLazy = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var internal_1 = require("./internal");
|
|
6
5
|
var AsyncOptLazy;
|
|
7
6
|
(function (AsyncOptLazy) {
|
|
8
7
|
/**
|
|
@@ -15,7 +14,12 @@ var AsyncOptLazy;
|
|
|
15
14
|
* AsyncOptLazy.toMaybePromise(async () => 1) // => Promise(1)
|
|
16
15
|
* AsyncOptLazy.toMaybePromise(Promise.resolve(1)) // => Promise(1)
|
|
17
16
|
*/
|
|
18
|
-
|
|
17
|
+
function toMaybePromise(optLazy) {
|
|
18
|
+
if (optLazy instanceof Function)
|
|
19
|
+
return optLazy();
|
|
20
|
+
return optLazy;
|
|
21
|
+
}
|
|
22
|
+
AsyncOptLazy.toMaybePromise = toMaybePromise;
|
|
19
23
|
/**
|
|
20
24
|
* Returns the value contained in an `AsyncOptLazy` instance of type T as a promise.
|
|
21
25
|
* @param optLazy - the `AsyncOptLazy` value of type T
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-optlazy.js","sourceRoot":"","sources":["../../src/async-optlazy.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"async-optlazy.js","sourceRoot":"","sources":["../../src/async-optlazy.ts"],"names":[],"mappings":";;;;AAcA,IAAiB,YAAY,CA8B5B;AA9BD,WAAiB,YAAY;IAC3B;;;;;;;;;OASG;IACH,SAAgB,cAAc,CAAI,OAAwB;QACxD,IAAI,OAAO,YAAY,QAAQ;YAAE,OAAO,OAAO,EAAE,CAAC;QAClD,OAAO,OAAO,CAAC;IACjB,CAAC;IAHe,2BAAc,iBAG7B,CAAA;IAED;;;;;;;;;OASG;IACH,SAAsB,SAAS,CAAI,OAAwB;;;gBACzD,IAAI,OAAO,YAAY,QAAQ;oBAAE,sBAAO,OAAO,EAAE,EAAC;gBAClD,sBAAO,OAAO,EAAC;;;KAChB;IAHqB,sBAAS,YAG9B,CAAA;AACH,CAAC,EA9BgB,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QA8B5B"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import { OptLazy } from './internal';
|
|
3
2
|
export var AsyncOptLazy;
|
|
4
3
|
(function (AsyncOptLazy) {
|
|
5
4
|
/**
|
|
@@ -12,7 +11,12 @@ export var AsyncOptLazy;
|
|
|
12
11
|
* AsyncOptLazy.toMaybePromise(async () => 1) // => Promise(1)
|
|
13
12
|
* AsyncOptLazy.toMaybePromise(Promise.resolve(1)) // => Promise(1)
|
|
14
13
|
*/
|
|
15
|
-
|
|
14
|
+
function toMaybePromise(optLazy) {
|
|
15
|
+
if (optLazy instanceof Function)
|
|
16
|
+
return optLazy();
|
|
17
|
+
return optLazy;
|
|
18
|
+
}
|
|
19
|
+
AsyncOptLazy.toMaybePromise = toMaybePromise;
|
|
16
20
|
/**
|
|
17
21
|
* Returns the value contained in an `AsyncOptLazy` instance of type T as a promise.
|
|
18
22
|
* @param optLazy - the `AsyncOptLazy` value of type T
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-optlazy.js","sourceRoot":"","sources":["../../src/async-optlazy.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"async-optlazy.js","sourceRoot":"","sources":["../../src/async-optlazy.ts"],"names":[],"mappings":";AAcA,MAAM,KAAW,YAAY,CA8B5B;AA9BD,WAAiB,YAAY;IAC3B;;;;;;;;;OASG;IACH,SAAgB,cAAc,CAAI,OAAwB;QACxD,IAAI,OAAO,YAAY,QAAQ;YAAE,OAAO,OAAO,EAAE,CAAC;QAClD,OAAO,OAAO,CAAC;IACjB,CAAC;IAHe,2BAAc,iBAG7B,CAAA;IAED;;;;;;;;;OASG;IACH,SAAsB,SAAS,CAAI,OAAwB;;YACzD,IAAI,OAAO,YAAY,QAAQ;gBAAE,OAAO,OAAO,EAAE,CAAC;YAClD,OAAO,OAAO,CAAC;QACjB,CAAC;KAAA;IAHqB,sBAAS,YAG9B,CAAA;AACH,CAAC,EA9BgB,YAAY,KAAZ,YAAY,QA8B5B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OptLazy } from './internal';
|
|
1
|
+
import type { OptLazy } from './internal';
|
|
2
2
|
/**
|
|
3
3
|
* A type that is either a value T or a promise yielding a value of type T.
|
|
4
4
|
* @typeparam T - the value type
|
|
@@ -20,7 +20,7 @@ export declare namespace AsyncOptLazy {
|
|
|
20
20
|
* AsyncOptLazy.toMaybePromise(async () => 1) // => Promise(1)
|
|
21
21
|
* AsyncOptLazy.toMaybePromise(Promise.resolve(1)) // => Promise(1)
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
function toMaybePromise<T>(optLazy: AsyncOptLazy<T>): MaybePromise<T>;
|
|
24
24
|
/**
|
|
25
25
|
* Returns the value contained in an `AsyncOptLazy` instance of type T as a promise.
|
|
26
26
|
* @param optLazy - the `AsyncOptLazy` value of type T
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rimbu/common",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Common types and objects used in many other Rimbu packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"common",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"tslib": "^2.3.1"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "d507e628ab82d501bc31351d69168e09bac5ae14"
|
|
65
65
|
}
|
package/src/async-optlazy.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OptLazy } from './internal';
|
|
1
|
+
import type { OptLazy } from './internal';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A type that is either a value T or a promise yielding a value of type T.
|
|
@@ -23,9 +23,10 @@ export namespace AsyncOptLazy {
|
|
|
23
23
|
* AsyncOptLazy.toMaybePromise(async () => 1) // => Promise(1)
|
|
24
24
|
* AsyncOptLazy.toMaybePromise(Promise.resolve(1)) // => Promise(1)
|
|
25
25
|
*/
|
|
26
|
-
export
|
|
27
|
-
optLazy
|
|
28
|
-
|
|
26
|
+
export function toMaybePromise<T>(optLazy: AsyncOptLazy<T>): MaybePromise<T> {
|
|
27
|
+
if (optLazy instanceof Function) return optLazy();
|
|
28
|
+
return optLazy;
|
|
29
|
+
}
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* Returns the value contained in an `AsyncOptLazy` instance of type T as a promise.
|