type-plus 4.15.2 → 4.17.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/README.md +9 -1
- package/cjs/function/ExtractFunction.d.ts +6 -0
- package/cjs/function/ExtractFunction.d.ts.map +1 -0
- package/cjs/function/ExtractFunction.js +3 -0
- package/cjs/function/ExtractFunction.js.map +1 -0
- package/cjs/function/ExtractFunction.spec.d.ts +2 -0
- package/cjs/function/ExtractFunction.spec.d.ts.map +1 -0
- package/cjs/function/ExtractFunction.spec.js +10 -0
- package/cjs/function/ExtractFunction.spec.js.map +1 -0
- package/cjs/function/index.d.ts +1 -0
- package/cjs/function/index.d.ts.map +1 -1
- package/cjs/index.d.ts +3 -3
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +0 -3
- package/cjs/index.js.map +1 -1
- package/cjs/promise/MaybePromise.d.ts +22 -0
- package/cjs/promise/MaybePromise.d.ts.map +1 -0
- package/cjs/promise/MaybePromise.js +12 -0
- package/cjs/promise/MaybePromise.js.map +1 -0
- package/cjs/promise/MaybePromise.spec.d.ts +2 -0
- package/cjs/promise/MaybePromise.spec.d.ts.map +1 -0
- package/cjs/promise/MaybePromise.spec.js +69 -0
- package/cjs/promise/MaybePromise.spec.js.map +1 -0
- package/cjs/promise/index.d.ts +2 -1
- package/cjs/promise/index.d.ts.map +1 -1
- package/cjs/promise/index.js +1 -0
- package/cjs/promise/index.js.map +1 -1
- package/esm/function/ExtractFunction.d.ts +6 -0
- package/esm/function/ExtractFunction.d.ts.map +1 -0
- package/esm/function/ExtractFunction.js +2 -0
- package/esm/function/ExtractFunction.js.map +1 -0
- package/esm/function/ExtractFunction.spec.d.ts +2 -0
- package/esm/function/ExtractFunction.spec.d.ts.map +1 -0
- package/esm/function/ExtractFunction.spec.js +8 -0
- package/esm/function/ExtractFunction.spec.js.map +1 -0
- package/esm/function/index.d.ts +1 -0
- package/esm/function/index.d.ts.map +1 -1
- package/esm/index.d.ts +3 -3
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +0 -3
- package/esm/index.js.map +1 -1
- package/esm/promise/MaybePromise.d.ts +22 -0
- package/esm/promise/MaybePromise.d.ts.map +1 -0
- package/esm/promise/MaybePromise.js +8 -0
- package/esm/promise/MaybePromise.js.map +1 -0
- package/esm/promise/MaybePromise.spec.d.ts +2 -0
- package/esm/promise/MaybePromise.spec.d.ts.map +1 -0
- package/esm/promise/MaybePromise.spec.js +21 -0
- package/esm/promise/MaybePromise.spec.js.map +1 -0
- package/esm/promise/index.d.ts +2 -1
- package/esm/promise/index.d.ts.map +1 -1
- package/esm/promise/index.js +1 -0
- package/esm/promise/index.js.map +1 -1
- package/package.json +5 -4
- package/ts/function/ExtractFunction.ts +7 -0
- package/ts/function/index.ts +1 -0
- package/ts/index.ts +3 -3
- package/ts/promise/MaybePromise.ts +28 -0
- package/ts/promise/index.ts +2 -1
package/README.md
CHANGED
|
@@ -368,12 +368,15 @@ JSONTypes.get<string>(someJson, 'a', 'b', 1, 'c') // miku
|
|
|
368
368
|
- `SpreadRecord<A, B>`: type for `{...a, ...b}` when both `a` and `b` are `Record`\
|
|
369
369
|
for array, just do `[...A, ...B]`.
|
|
370
370
|
|
|
371
|
-
### Promise
|
|
371
|
+
### Promise utilities
|
|
372
372
|
|
|
373
373
|
- `isPromise<R>(subject: any)`: `isPromise()` type guard.
|
|
374
|
+
- `MaybePromise<T>`: Alias of `T | Promise<T>`.
|
|
374
375
|
- `PromiseValue<P>`: Gets the type within the Promise.
|
|
375
376
|
- `PromiseValueMerge<P1, P2, ...P9>`: Merge the values of multiple promises.
|
|
376
377
|
- `mapSeries()`: Similar to `bluebird.mapSeries()` but works with `async`/`await`.
|
|
378
|
+
- `transformMaybePromise(value, transformer)`: Apply the `transformer` to the `value`.\
|
|
379
|
+
It is also exported under `MaybePromise.transform()`.
|
|
377
380
|
|
|
378
381
|
### Type manipulation
|
|
379
382
|
|
|
@@ -549,6 +552,11 @@ const b2 = brand('y', 1)
|
|
|
549
552
|
nominalMatch(b1, b2) // false
|
|
550
553
|
```
|
|
551
554
|
|
|
555
|
+
## Function Types
|
|
556
|
+
|
|
557
|
+
- `AnyFunction<P, R>`: a generic type for any function
|
|
558
|
+
- `ExtractFunction<F>`: extract the function signature from a type `F`.
|
|
559
|
+
|
|
552
560
|
## Functional Types
|
|
553
561
|
|
|
554
562
|
- `ChainFn<T>: T`: chain function that returns the input type.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AnyFunction } from './AnyFunction.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extract the function signature from a composit type T.
|
|
4
|
+
*/
|
|
5
|
+
export declare type ExtractFunction<T extends AnyFunction> = T extends AnyFunction<infer P, infer R> ? (...args: P) => R : never;
|
|
6
|
+
//# sourceMappingURL=ExtractFunction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtractFunction.d.ts","sourceRoot":"","sources":["../../ts/function/ExtractFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C;;GAEG;AACH,oBAAY,eAAe,CAAC,CAAC,SAAS,WAAW,IAAI,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GACxF,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtractFunction.js","sourceRoot":"","sources":["../../ts/function/ExtractFunction.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtractFunction.spec.d.ts","sourceRoot":"","sources":["../../ts/function/ExtractFunction.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_js_1 = require("../index.js");
|
|
4
|
+
it('gets the function itself if it is not composite', function () {
|
|
5
|
+
index_js_1.isType.equal();
|
|
6
|
+
});
|
|
7
|
+
it('omits other props from the type', function () {
|
|
8
|
+
index_js_1.isType.equal();
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=ExtractFunction.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtractFunction.spec.js","sourceRoot":"","sources":["../../ts/function/ExtractFunction.spec.ts"],"names":[],"mappings":";;AAAA,wCAAoC;AAGpC,EAAE,CAAC,iDAAiD,EAAE;IAIpD,iBAAM,CAAC,KAAK,EAAc,CAAA;AAC5B,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,iCAAiC,EAAE;IAIpC,iBAAM,CAAC,KAAK,EAAuB,CAAA;AACrC,CAAC,CAAC,CAAA"}
|
package/cjs/function/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../ts/function/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../ts/function/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA"}
|
package/cjs/index.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ export * from './array/index.js';
|
|
|
3
3
|
export * from './assertion/index.js';
|
|
4
4
|
export * from './class/index.js';
|
|
5
5
|
export type { ComposableTypes, NonComposableTypes } from './ComposableTypes.js';
|
|
6
|
-
export
|
|
6
|
+
export type { AnyFunction, ExtractFunction } from './function/index.js';
|
|
7
7
|
export * from './functional/index.js';
|
|
8
|
-
export
|
|
9
|
-
export
|
|
8
|
+
export type { JSONArray, JSONObject, JSONPrimitive, JSONTypes } from './JSONTypes.js';
|
|
9
|
+
export type { Abs, Add, Decrement, Digit, DigitArray, GreaterThan, Increment, IsPositive, IsWhole, Max, Subtract } from './math/index.js';
|
|
10
10
|
export * from './nodejs/index.js';
|
|
11
11
|
export * from './nominal-types/index.js';
|
|
12
12
|
export * from './object/index.js';
|
package/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC7D,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAC/E,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC7D,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAC/E,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACvE,cAAc,uBAAuB,CAAA;AACrC,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACrF,YAAY,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AACzI,cAAc,mBAAmB,CAAA;AACjC,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClE,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAGlC,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,cAAc,kBAAkB,CAAA"}
|
package/cjs/index.js
CHANGED
|
@@ -23,10 +23,7 @@ Object.defineProperty(exports, "unpartial", { enumerable: true, get: function ()
|
|
|
23
23
|
__exportStar(require("./array/index.js"), exports);
|
|
24
24
|
__exportStar(require("./assertion/index.js"), exports);
|
|
25
25
|
__exportStar(require("./class/index.js"), exports);
|
|
26
|
-
__exportStar(require("./function/index.js"), exports);
|
|
27
26
|
__exportStar(require("./functional/index.js"), exports);
|
|
28
|
-
__exportStar(require("./JSONTypes.js"), exports);
|
|
29
|
-
__exportStar(require("./math/index.js"), exports);
|
|
30
27
|
__exportStar(require("./nodejs/index.js"), exports);
|
|
31
28
|
__exportStar(require("./nominal-types/index.js"), exports);
|
|
32
29
|
__exportStar(require("./object/index.js"), exports);
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4CAA4C;AAC5C,uCAA6D;AAApD,qGAAA,QAAQ,OAAA;AAAE,yGAAA,YAAY,OAAA;AAAE,sGAAA,SAAS,OAAA;AAC1C,mDAAgC;AAChC,uDAAoC;AACpC,mDAAgC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4CAA4C;AAC5C,uCAA6D;AAApD,qGAAA,QAAQ,OAAA;AAAE,yGAAA,YAAY,OAAA;AAAE,sGAAA,SAAS,OAAA;AAC1C,mDAAgC;AAChC,uDAAoC;AACpC,mDAAgC;AAGhC,wDAAqC;AAGrC,oDAAiC;AACjC,2DAAwC;AACxC,oDAAiC;AACjC,wDAAqC;AAErC,qDAAkC;AAClC,qDAAkC;AAIlC,mDAAgC;AAChC,+BAA+B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `T | Promise<T>`
|
|
3
|
+
*/
|
|
4
|
+
export declare type MaybePromise<T> = T | Promise<T>;
|
|
5
|
+
/**
|
|
6
|
+
* Transforms the value within the promise.
|
|
7
|
+
*
|
|
8
|
+
* @return a new promise with the transformed result.
|
|
9
|
+
*/
|
|
10
|
+
export declare function transformMaybePromise<T, R>(value: Promise<T>, transformer: (value: T) => R): Promise<R>;
|
|
11
|
+
/**
|
|
12
|
+
* Transforms the value, or if the value is a promise,
|
|
13
|
+
* transform the resolved value of the promise.
|
|
14
|
+
*
|
|
15
|
+
* @return the transformed result,
|
|
16
|
+
* or if the value is a promise, a new promse with the transformed result.
|
|
17
|
+
*/
|
|
18
|
+
export declare function transformMaybePromise<T, R>(value: T, transformer: (value: T) => R): T extends Promise<any> ? Promise<R> : R;
|
|
19
|
+
export declare const MaybePromise: {
|
|
20
|
+
transform: typeof transformMaybePromise;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=MaybePromise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaybePromise.d.ts","sourceRoot":"","sources":["../../ts/promise/MaybePromise.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,oBAAY,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AAE5C;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AACxG;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAK5H,eAAO,MAAM,YAAY;;CAExB,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MaybePromise = exports.transformMaybePromise = void 0;
|
|
4
|
+
var isPromise_js_1 = require("./isPromise.js");
|
|
5
|
+
function transformMaybePromise(value, transformer) {
|
|
6
|
+
return (0, isPromise_js_1.isPromise)(value) ? value.then(transformer) : transformer(value);
|
|
7
|
+
}
|
|
8
|
+
exports.transformMaybePromise = transformMaybePromise;
|
|
9
|
+
exports.MaybePromise = {
|
|
10
|
+
transform: transformMaybePromise
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=MaybePromise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaybePromise.js","sourceRoot":"","sources":["../../ts/promise/MaybePromise.ts"],"names":[],"mappings":";;;AAAA,+CAA0C;AAqB1C,SAAgB,qBAAqB,CAAO,KAAsB,EAAE,WAA4B;IAC9F,OAAO,IAAA,wBAAS,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;AACxE,CAAC;AAFD,sDAEC;AAEY,QAAA,YAAY,GAAG;IAC1B,SAAS,EAAE,qBAAqB;CACjC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaybePromise.spec.d.ts","sourceRoot":"","sources":["../../ts/promise/MaybePromise.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var index_js_1 = require("../index.js");
|
|
40
|
+
describe("".concat(index_js_1.MaybePromise.transform.name, "()"), function () {
|
|
41
|
+
it('returns the result from the handler directly if it is not a promise', function () {
|
|
42
|
+
var r = index_js_1.MaybePromise.transform(1, function (v) { return String(v); });
|
|
43
|
+
index_js_1.isType.equal();
|
|
44
|
+
expect(r).toEqual('1');
|
|
45
|
+
});
|
|
46
|
+
it('returns a promise that resolves to the result from the handler', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
47
|
+
var r, _a;
|
|
48
|
+
return __generator(this, function (_b) {
|
|
49
|
+
switch (_b.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
r = index_js_1.MaybePromise.transform(Promise.resolve(1), function (v) { return String(v); });
|
|
52
|
+
index_js_1.isType.equal();
|
|
53
|
+
expect(r).not.toEqual('1');
|
|
54
|
+
_a = expect;
|
|
55
|
+
return [4 /*yield*/, r];
|
|
56
|
+
case 1:
|
|
57
|
+
_a.apply(void 0, [_b.sent()]).toEqual('1');
|
|
58
|
+
return [2 /*return*/];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}); });
|
|
62
|
+
it('preserves the type of it is MaybePromise', function () {
|
|
63
|
+
var v = 1;
|
|
64
|
+
var r = index_js_1.MaybePromise.transform(v, function (v) { return String(v); });
|
|
65
|
+
index_js_1.isType.equal();
|
|
66
|
+
expect(r).toEqual('1');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=MaybePromise.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaybePromise.spec.js","sourceRoot":"","sources":["../../ts/promise/MaybePromise.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAkD;AAElD,QAAQ,CAAC,UAAG,uBAAY,CAAC,SAAS,CAAC,IAAI,OAAI,EAAE;IAC3C,EAAE,CAAC,qEAAqE,EAAE;QACxE,IAAM,CAAC,GAAG,uBAAY,CAAC,SAAS,CAAC,CAAC,EAAE,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,CAAC,CAAC,EAAT,CAAS,CAAC,CAAA;QAEnD,iBAAM,CAAC,KAAK,EAA0B,CAAA;QACtC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACxB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,gEAAgE,EAAE;;;;;oBAC7D,CAAC,GAAG,uBAAY,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,CAAC,CAAC,EAAT,CAAS,CAAC,CAAA;oBAEpE,iBAAM,CAAC,KAAK,EAAmC,CAAA;oBAC/C,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;oBAC1B,KAAA,MAAM,CAAA;oBAAC,qBAAM,CAAC,EAAA;;oBAAd,kBAAO,SAAO,EAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;;;;SAC7B,CAAC,CAAA;IAEF,EAAE,CAAC,0CAA0C,EAAE;QAC7C,IAAM,CAAC,GAAyB,CAAyB,CAAA;QACzD,IAAM,CAAC,GAAG,uBAAY,CAAC,SAAS,CAAC,CAAC,EAAE,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,CAAC,CAAC,EAAT,CAAS,CAAC,CAAA;QACnD,iBAAM,CAAC,KAAK,EAA4C,CAAA;QACxD,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACxB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/cjs/promise/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './isPromise.js';
|
|
2
|
+
export * from './mapSeries.js';
|
|
3
|
+
export * from './MaybePromise.js';
|
|
2
4
|
export type { PromiseValue } from './PromiseValue.js';
|
|
3
5
|
export type { PromiseValueMerge } from './PromiseValueMerge.js';
|
|
4
|
-
export * from './mapSeries.js';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../ts/promise/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../ts/promise/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA"}
|
package/cjs/promise/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./isPromise.js"), exports);
|
|
18
18
|
__exportStar(require("./mapSeries.js"), exports);
|
|
19
|
+
__exportStar(require("./MaybePromise.js"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
package/cjs/promise/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/promise/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/promise/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B;AAC9B,iDAA8B;AAC9B,oDAAiC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AnyFunction } from './AnyFunction.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extract the function signature from a composit type T.
|
|
4
|
+
*/
|
|
5
|
+
export declare type ExtractFunction<T extends AnyFunction> = T extends AnyFunction<infer P, infer R> ? (...args: P) => R : never;
|
|
6
|
+
//# sourceMappingURL=ExtractFunction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtractFunction.d.ts","sourceRoot":"","sources":["../../ts/function/ExtractFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C;;GAEG;AACH,oBAAY,eAAe,CAAC,CAAC,SAAS,WAAW,IAAI,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GACxF,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtractFunction.js","sourceRoot":"","sources":["../../ts/function/ExtractFunction.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtractFunction.spec.d.ts","sourceRoot":"","sources":["../../ts/function/ExtractFunction.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtractFunction.spec.js","sourceRoot":"","sources":["../../ts/function/ExtractFunction.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGpC,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;IAIzD,MAAM,CAAC,KAAK,EAAc,CAAA;AAC5B,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;IAIzC,MAAM,CAAC,KAAK,EAAuB,CAAA;AACrC,CAAC,CAAC,CAAA"}
|
package/esm/function/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../ts/function/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../ts/function/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA"}
|
package/esm/index.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ export * from './array/index.js';
|
|
|
3
3
|
export * from './assertion/index.js';
|
|
4
4
|
export * from './class/index.js';
|
|
5
5
|
export type { ComposableTypes, NonComposableTypes } from './ComposableTypes.js';
|
|
6
|
-
export
|
|
6
|
+
export type { AnyFunction, ExtractFunction } from './function/index.js';
|
|
7
7
|
export * from './functional/index.js';
|
|
8
|
-
export
|
|
9
|
-
export
|
|
8
|
+
export type { JSONArray, JSONObject, JSONPrimitive, JSONTypes } from './JSONTypes.js';
|
|
9
|
+
export type { Abs, Add, Decrement, Digit, DigitArray, GreaterThan, Increment, IsPositive, IsWhole, Max, Subtract } from './math/index.js';
|
|
10
10
|
export * from './nodejs/index.js';
|
|
11
11
|
export * from './nominal-types/index.js';
|
|
12
12
|
export * from './object/index.js';
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC7D,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAC/E,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC7D,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAC/E,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACvE,cAAc,uBAAuB,CAAA;AACrC,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACrF,YAAY,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AACzI,cAAc,mBAAmB,CAAA;AACjC,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClE,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAGlC,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,cAAc,kBAAkB,CAAA"}
|
package/esm/index.js
CHANGED
|
@@ -3,10 +3,7 @@ export { required, requiredDeep, unpartial } from 'unpartial';
|
|
|
3
3
|
export * from './array/index.js';
|
|
4
4
|
export * from './assertion/index.js';
|
|
5
5
|
export * from './class/index.js';
|
|
6
|
-
export * from './function/index.js';
|
|
7
6
|
export * from './functional/index.js';
|
|
8
|
-
export * from './JSONTypes.js';
|
|
9
|
-
export * from './math/index.js';
|
|
10
7
|
export * from './nodejs/index.js';
|
|
11
8
|
export * from './nominal-types/index.js';
|
|
12
9
|
export * from './object/index.js';
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC7D,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC7D,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAGhC,cAAc,uBAAuB,CAAA;AAGrC,cAAc,mBAAmB,CAAA;AACjC,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AAErC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAIlC,cAAc,kBAAkB,CAAA;AAChC,+BAA+B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `T | Promise<T>`
|
|
3
|
+
*/
|
|
4
|
+
export declare type MaybePromise<T> = T | Promise<T>;
|
|
5
|
+
/**
|
|
6
|
+
* Transforms the value within the promise.
|
|
7
|
+
*
|
|
8
|
+
* @return a new promise with the transformed result.
|
|
9
|
+
*/
|
|
10
|
+
export declare function transformMaybePromise<T, R>(value: Promise<T>, transformer: (value: T) => R): Promise<R>;
|
|
11
|
+
/**
|
|
12
|
+
* Transforms the value, or if the value is a promise,
|
|
13
|
+
* transform the resolved value of the promise.
|
|
14
|
+
*
|
|
15
|
+
* @return the transformed result,
|
|
16
|
+
* or if the value is a promise, a new promse with the transformed result.
|
|
17
|
+
*/
|
|
18
|
+
export declare function transformMaybePromise<T, R>(value: T, transformer: (value: T) => R): T extends Promise<any> ? Promise<R> : R;
|
|
19
|
+
export declare const MaybePromise: {
|
|
20
|
+
transform: typeof transformMaybePromise;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=MaybePromise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaybePromise.d.ts","sourceRoot":"","sources":["../../ts/promise/MaybePromise.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,oBAAY,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AAE5C;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AACxG;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAK5H,eAAO,MAAM,YAAY;;CAExB,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { isPromise } from './isPromise.js';
|
|
2
|
+
export function transformMaybePromise(value, transformer) {
|
|
3
|
+
return isPromise(value) ? value.then(transformer) : transformer(value);
|
|
4
|
+
}
|
|
5
|
+
export const MaybePromise = {
|
|
6
|
+
transform: transformMaybePromise
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=MaybePromise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaybePromise.js","sourceRoot":"","sources":["../../ts/promise/MaybePromise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAqB1C,MAAM,UAAU,qBAAqB,CAAO,KAAsB,EAAE,WAA4B;IAC9F,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;AACxE,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,SAAS,EAAE,qBAAqB;CACjC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaybePromise.spec.d.ts","sourceRoot":"","sources":["../../ts/promise/MaybePromise.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isType, MaybePromise } from '../index.js';
|
|
2
|
+
describe(`${MaybePromise.transform.name}()`, () => {
|
|
3
|
+
it('returns the result from the handler directly if it is not a promise', () => {
|
|
4
|
+
const r = MaybePromise.transform(1, v => String(v));
|
|
5
|
+
isType.equal();
|
|
6
|
+
expect(r).toEqual('1');
|
|
7
|
+
});
|
|
8
|
+
it('returns a promise that resolves to the result from the handler', async () => {
|
|
9
|
+
const r = MaybePromise.transform(Promise.resolve(1), v => String(v));
|
|
10
|
+
isType.equal();
|
|
11
|
+
expect(r).not.toEqual('1');
|
|
12
|
+
expect(await r).toEqual('1');
|
|
13
|
+
});
|
|
14
|
+
it('preserves the type of it is MaybePromise', () => {
|
|
15
|
+
const v = 1;
|
|
16
|
+
const r = MaybePromise.transform(v, v => String(v));
|
|
17
|
+
isType.equal();
|
|
18
|
+
expect(r).toEqual('1');
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=MaybePromise.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaybePromise.spec.js","sourceRoot":"","sources":["../../ts/promise/MaybePromise.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAElD,QAAQ,CAAC,GAAG,YAAY,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE,GAAG,EAAE;IAChD,EAAE,CAAC,qEAAqE,EAAE,GAAG,EAAE;QAC7E,MAAM,CAAC,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;QAEnD,MAAM,CAAC,KAAK,EAA0B,CAAA;QACtC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACxB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,gEAAgE,EAAE,KAAK,IAAI,EAAE;QAC9E,MAAM,CAAC,GAAG,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;QAEpE,MAAM,CAAC,KAAK,EAAmC,CAAA;QAC/C,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAC1B,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAC9B,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,CAAC,GAAyB,CAAyB,CAAA;QACzD,MAAM,CAAC,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;QACnD,MAAM,CAAC,KAAK,EAA4C,CAAA;QACxD,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACxB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/esm/promise/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './isPromise.js';
|
|
2
|
+
export * from './mapSeries.js';
|
|
3
|
+
export * from './MaybePromise.js';
|
|
2
4
|
export type { PromiseValue } from './PromiseValue.js';
|
|
3
5
|
export type { PromiseValueMerge } from './PromiseValueMerge.js';
|
|
4
|
-
export * from './mapSeries.js';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../ts/promise/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../ts/promise/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA"}
|
package/esm/promise/index.js
CHANGED
package/esm/promise/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/promise/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/promise/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-plus",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.17.0",
|
|
4
4
|
"description": "Provides additional types for TypeScript.",
|
|
5
5
|
"homepage": "https://github.com/unional/type-plus",
|
|
6
6
|
"bugs": {
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
],
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "run-p build:cjs build:esm build:tslib",
|
|
36
|
-
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
36
|
+
"build:cjs": "tsc -p tsconfig.cjs.json && ncp package.cjs.json cjs/package.json",
|
|
37
37
|
"build:esm": "tsc -p tsconfig.esm.json",
|
|
38
|
-
"build:tslib": "tsc -p tsconfig.tslib.json",
|
|
38
|
+
"build:tslib": "tsc -p tsconfig.tslib.json && ncp package.cjs.json tslib/package.json",
|
|
39
39
|
"build:doc": "typedoc",
|
|
40
|
-
"clean": "rimraf cjs coverage esm lib libm
|
|
40
|
+
"clean": "rimraf cjs coverage esm lib libm",
|
|
41
41
|
"coverage": "jest --coverage",
|
|
42
42
|
"depcheck": "depcheck",
|
|
43
43
|
"lint": "eslint --ext=ts,js .",
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"jest-watch-suspend": "^1.1.2",
|
|
75
75
|
"jest-watch-toggle-config": "^2.0.1",
|
|
76
76
|
"jest-watch-typeahead": "^2.0.0",
|
|
77
|
+
"ncp": "^2.0.0",
|
|
77
78
|
"npm-run-all": "^4.1.5",
|
|
78
79
|
"pinst": "^3.0.0",
|
|
79
80
|
"rimraf": "^3.0.2",
|
package/ts/function/index.ts
CHANGED
package/ts/index.ts
CHANGED
|
@@ -4,10 +4,10 @@ export * from './array/index.js'
|
|
|
4
4
|
export * from './assertion/index.js'
|
|
5
5
|
export * from './class/index.js'
|
|
6
6
|
export type { ComposableTypes, NonComposableTypes } from './ComposableTypes.js'
|
|
7
|
-
export
|
|
7
|
+
export type { AnyFunction, ExtractFunction } from './function/index.js'
|
|
8
8
|
export * from './functional/index.js'
|
|
9
|
-
export
|
|
10
|
-
export
|
|
9
|
+
export type { JSONArray, JSONObject, JSONPrimitive, JSONTypes } from './JSONTypes.js'
|
|
10
|
+
export type { Abs, Add, Decrement, Digit, DigitArray, GreaterThan, Increment, IsPositive, IsWhole, Max, Subtract } from './math/index.js'
|
|
11
11
|
export * from './nodejs/index.js'
|
|
12
12
|
export * from './nominal-types/index.js'
|
|
13
13
|
export * from './object/index.js'
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isPromise } from './isPromise.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `T | Promise<T>`
|
|
5
|
+
*/
|
|
6
|
+
export type MaybePromise<T> = T | Promise<T>
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Transforms the value within the promise.
|
|
10
|
+
*
|
|
11
|
+
* @return a new promise with the transformed result.
|
|
12
|
+
*/
|
|
13
|
+
export function transformMaybePromise<T, R>(value: Promise<T>, transformer: (value: T) => R): Promise<R>
|
|
14
|
+
/**
|
|
15
|
+
* Transforms the value, or if the value is a promise,
|
|
16
|
+
* transform the resolved value of the promise.
|
|
17
|
+
*
|
|
18
|
+
* @return the transformed result,
|
|
19
|
+
* or if the value is a promise, a new promse with the transformed result.
|
|
20
|
+
*/
|
|
21
|
+
export function transformMaybePromise<T, R>(value: T, transformer: (value: T) => R): T extends Promise<any> ? Promise<R> : R
|
|
22
|
+
export function transformMaybePromise<T, R>(value: MaybePromise<T>, transformer: (value: T) => R) {
|
|
23
|
+
return isPromise(value) ? value.then(transformer) : transformer(value)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const MaybePromise = {
|
|
27
|
+
transform: transformMaybePromise
|
|
28
|
+
}
|
package/ts/promise/index.ts
CHANGED