type-fns 0.10.0 → 1.13.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/checks/isAPromise.test.js.map +1 -1
- package/dist/checks/isNotNull.test.js.map +1 -1
- package/dist/checks/isNotUndefined.d.ts +16 -2
- package/dist/checks/isNotUndefined.js +10 -2
- package/dist/checks/isNotUndefined.js.map +1 -1
- package/dist/checks/isNotUndefined.test.js.map +1 -1
- package/dist/checks/isOfEnum.d.ts +1 -11
- package/dist/checks/isOfEnum.js +3 -13
- package/dist/checks/isOfEnum.js.map +1 -1
- package/dist/checks/isOfEnum.test.js.map +1 -1
- package/dist/checks/isPresent.d.ts +13 -2
- package/dist/checks/isPresent.js +13 -3
- package/dist/checks/isPresent.js.map +1 -1
- package/dist/checks/isPresent.test.js +69 -16
- package/dist/checks/isPresent.test.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/types/Literalize.d.ts +25 -0
- package/dist/types/Literalize.js +3 -0
- package/dist/types/Literalize.js.map +1 -0
- package/dist/types/Literalize.test.d.ts +1 -0
- package/dist/types/Literalize.test.js +18 -0
- package/dist/types/Literalize.test.js.map +1 -0
- package/dist/types/PickOne.test.js +1 -1
- package/dist/types/PickOne.test.js.map +1 -1
- package/dist/utils/environment.js +1 -1
- package/dist/utils/environment.js.map +1 -1
- package/dist/wrappers/withAssure.d.ts +42 -0
- package/dist/wrappers/withAssure.js +58 -0
- package/dist/wrappers/withAssure.js.map +1 -0
- package/dist/wrappers/withAssure.test.d.ts +1 -0
- package/dist/wrappers/withAssure.test.js +49 -0
- package/dist/wrappers/withAssure.test.js.map +1 -0
- package/dist/wrappers/withNot.d.ts +1 -1
- package/package.json +11 -7
- package/dist/types/NotUndefined.d.ts +0 -0
- package/dist/types/NotUndefined.js +0 -2
- package/dist/types/NotUndefined.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isAPromise.test.js","sourceRoot":"","sources":["../../src/checks/isAPromise.test.ts"],"names":[],"mappings":";;AAAA,6CAA0C;AAE1C,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,SAAS,GAAG,IAAA,uBAAU,EAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QACvD,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,MAAM,SAAS,GAAG,IAAA,uBAAU,EAAC,OAAO,CAAC,CAAC;QACtC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,wEAAwE;QACxE,MAAM,aAAa,GAA6B,OAAO,CAAC,OAAO,CAC7D,OAAO,CACD,CAAC;QAET,mGAAmG;QACnG,IAAI,IAAA,uBAAU,EAAC,aAAa,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"isAPromise.test.js","sourceRoot":"","sources":["../../src/checks/isAPromise.test.ts"],"names":[],"mappings":";;AAAA,6CAA0C;AAE1C,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,SAAS,GAAG,IAAA,uBAAU,EAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QACvD,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,MAAM,SAAS,GAAG,IAAA,uBAAU,EAAC,OAAO,CAAC,CAAC;QACtC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,wEAAwE;QACxE,MAAM,aAAa,GAA6B,OAAO,CAAC,OAAO,CAC7D,OAAO,CACD,CAAC;QAET,mGAAmG;QACnG,IAAI,IAAA,uBAAU,EAAC,aAAa,CAAC,EAAE,CAAC;YAC9B,KAAK,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;QACxC,CAAC;aAAM,CAAC;YACN,KAAK,aAAa,CAAC,WAAW,EAAE,CAAC;QACnC,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isNotNull.test.js","sourceRoot":"","sources":["../../src/checks/isNotNull.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sDAAsD;AACtD,0BAAwC;AAExC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,iCAAiC,EAAE,GAAS,EAAE;QAG/C,MAAM,WAAW,GAAgB,SAAgB,CAAC,CAAC,QAAQ;QAE3D,IAAI,IAAA,aAAS,EAAC,WAAW,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"isNotNull.test.js","sourceRoot":"","sources":["../../src/checks/isNotNull.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sDAAsD;AACtD,0BAAwC;AAExC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,iCAAiC,EAAE,GAAS,EAAE;QAG/C,MAAM,WAAW,GAAgB,SAAgB,CAAC,CAAC,QAAQ;QAE3D,IAAI,IAAA,aAAS,EAAC,WAAW,CAAC,EAAE,CAAC;YAC3B,MAAM,SAAS,GAAW,WAAW,CAAC,CAAC,QAAQ;QACjD,CAAC;IACH,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,iCAAiC,EAAE,GAAS,EAAE;QAG/C,MAAM,cAAc,GAAyB,GAAU,CAAC;QACxD,MAAM,UAAU,GAAW,cAAc,CAAC,CAAC,QAAQ;IACrD,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -4,8 +4,22 @@
|
|
|
4
4
|
* ref
|
|
5
5
|
* - https://stackoverflow.com/a/63045455/3068233
|
|
6
6
|
*/
|
|
7
|
-
export type
|
|
7
|
+
export type IsDefined<T> = T extends undefined ? never : T;
|
|
8
|
+
/**
|
|
9
|
+
* narrows the type to remove undefined
|
|
10
|
+
*
|
|
11
|
+
* note
|
|
12
|
+
* - alias of IsDefined
|
|
13
|
+
*/
|
|
14
|
+
export type NotUndefined<T> = IsDefined<T>;
|
|
8
15
|
/**
|
|
9
16
|
* checks whether the value is not undefined
|
|
10
17
|
*/
|
|
11
|
-
export declare const
|
|
18
|
+
export declare const isDefined: <T>(val: T) => val is IsDefined<T>;
|
|
19
|
+
/**
|
|
20
|
+
* checks whether the value is not undefined
|
|
21
|
+
*
|
|
22
|
+
* note
|
|
23
|
+
* - alias of isDefined
|
|
24
|
+
*/
|
|
25
|
+
export declare const isNotUndefined: <T>(val: T) => val is IsDefined<T>;
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNotUndefined = void 0;
|
|
3
|
+
exports.isNotUndefined = exports.isDefined = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* checks whether the value is not undefined
|
|
6
6
|
*/
|
|
7
|
-
const
|
|
7
|
+
const isDefined = (val) => typeof val !== 'undefined';
|
|
8
|
+
exports.isDefined = isDefined;
|
|
9
|
+
/**
|
|
10
|
+
* checks whether the value is not undefined
|
|
11
|
+
*
|
|
12
|
+
* note
|
|
13
|
+
* - alias of isDefined
|
|
14
|
+
*/
|
|
15
|
+
const isNotUndefined = (val) => (0, exports.isDefined)(val);
|
|
8
16
|
exports.isNotUndefined = isNotUndefined;
|
|
9
17
|
//# sourceMappingURL=isNotUndefined.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isNotUndefined.js","sourceRoot":"","sources":["../../src/checks/isNotUndefined.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"isNotUndefined.js","sourceRoot":"","sources":["../../src/checks/isNotUndefined.ts"],"names":[],"mappings":";;;AAgBA;;GAEG;AACI,MAAM,SAAS,GAAG,CAAI,GAAM,EAAuB,EAAE,CAC1D,OAAO,GAAG,KAAK,WAAW,CAAC;AADhB,QAAA,SAAS,aACO;AAE7B;;;;;GAKG;AACI,MAAM,cAAc,GAAG,CAAI,GAAM,EAA0B,EAAE,CAClE,IAAA,iBAAS,EAAC,GAAG,CAAC,CAAC;AADJ,QAAA,cAAc,kBACV"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isNotUndefined.test.js","sourceRoot":"","sources":["../../src/checks/isNotUndefined.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sDAAsD;AACtD,0BAAkD;AAElD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,iCAAiC,EAAE,GAAS,EAAE;QAG/C,MAAM,WAAW,GAAgB,SAAgB,CAAC,CAAC,QAAQ;QAE3D,IAAI,IAAA,kBAAc,EAAC,WAAW,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"isNotUndefined.test.js","sourceRoot":"","sources":["../../src/checks/isNotUndefined.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sDAAsD;AACtD,0BAAkD;AAElD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,iCAAiC,EAAE,GAAS,EAAE;QAG/C,MAAM,WAAW,GAAgB,SAAgB,CAAC,CAAC,QAAQ;QAE3D,IAAI,IAAA,kBAAc,EAAC,WAAW,CAAC,EAAE,CAAC;YAChC,MAAM,SAAS,GAAW,WAAW,CAAC,CAAC,QAAQ;QACjD,CAAC;IACH,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,iCAAiC,EAAE,GAAS,EAAE;QAG/C,MAAM,cAAc,GAA8B,GAAU,CAAC;QAC7D,MAAM,UAAU,GAAW,cAAc,CAAC,CAAC,QAAQ;IACrD,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
type AssessMethod<T extends {
|
|
2
|
-
[index: string | number | symbol]: string | number;
|
|
3
|
-
}> = (token: string | number | symbol) => token is T[keyof T] & ((token: string | number | symbol) => boolean);
|
|
4
|
-
type AssureMethod<T extends {
|
|
5
|
-
[index: string | number | symbol]: string | number;
|
|
6
|
-
}> = <I extends string | number | symbol>(input: I) => I & T[keyof T];
|
|
7
1
|
/**
|
|
8
2
|
* a generic fn that allows us to create type checks for enums. for example:
|
|
9
3
|
* ```ts
|
|
@@ -32,8 +26,4 @@ export declare const createIsOfEnum: <T extends {
|
|
|
32
26
|
[index: string]: string | number;
|
|
33
27
|
[index: number]: string | number;
|
|
34
28
|
[index: symbol]: string | number;
|
|
35
|
-
}>(e: T) =>
|
|
36
|
-
assess: AssessMethod<T>;
|
|
37
|
-
assure: AssureMethod<T>;
|
|
38
|
-
} & AssessMethod<T>;
|
|
39
|
-
export {};
|
|
29
|
+
}>(e: T) => import("../wrappers/withAssure").AssessWithAssure<string | number | symbol, T[keyof T]>;
|
package/dist/checks/isOfEnum.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createIsOfEnum = void 0;
|
|
4
|
-
const
|
|
4
|
+
const withAssure_1 = require("../wrappers/withAssure");
|
|
5
5
|
/**
|
|
6
6
|
* a generic fn that allows us to create type checks for enums. for example:
|
|
7
7
|
* ```ts
|
|
@@ -27,18 +27,8 @@ const UnexpectedCodePathError_1 = require("../utils/errors/UnexpectedCodePathErr
|
|
|
27
27
|
* ref: https://stackoverflow.com/a/58278753/3068233
|
|
28
28
|
*/
|
|
29
29
|
const createIsOfEnum = (e) => {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
? input
|
|
33
|
-
: (() => {
|
|
34
|
-
throw new UnexpectedCodePathError_1.UnexpectedCodePathError('is not of DeclaredGoogleAdsCriterionUserInterestTaxonomy');
|
|
35
|
-
})();
|
|
36
|
-
const result = function (...input) {
|
|
37
|
-
return assess(...input);
|
|
38
|
-
};
|
|
39
|
-
result.assess = assess;
|
|
40
|
-
result.assure = assure;
|
|
41
|
-
return result;
|
|
30
|
+
const check = (token) => Object.values(e).includes(token);
|
|
31
|
+
return (0, withAssure_1.withAssure)(check);
|
|
42
32
|
};
|
|
43
33
|
exports.createIsOfEnum = createIsOfEnum;
|
|
44
34
|
//# sourceMappingURL=isOfEnum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isOfEnum.js","sourceRoot":"","sources":["../../src/checks/isOfEnum.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"isOfEnum.js","sourceRoot":"","sources":["../../src/checks/isOfEnum.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAEpD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,cAAc,GAAG,CAG5B,CAAI,EACJ,EAAE;IACF,MAAM,KAAK,GAAG,CAAC,KAA+B,EAAuB,EAAE,CACrE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAmB,CAAC,CAAC;IACjD,OAAO,IAAA,uBAAU,EAAC,KAAK,CAAC,CAAC;AAC3B,CAAC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,CAAC;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC;QACtB,IAAI,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,GAAW,KAAK,CAAC,CAAC,gBAAgB;QAC9C,CAAC;IACH,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,QAAQ,GAAG,IAAA,yBAAc,EAAC,MAAM,CAAC,CAAC;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC;QACtB,MAAM,IAAI,GAAW,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
import { NotNull } from './isNotNull';
|
|
2
|
+
import { IsDefined } from './isNotUndefined';
|
|
3
|
+
declare const assess: <T>(t: T) => t is NotNull<IsDefined<T>>;
|
|
4
|
+
declare const assure: <T>(input: T) => NotNull<IsDefined<T>>;
|
|
5
|
+
interface IsPresentWithAssure {
|
|
6
|
+
<T>(t: T): t is NotNull<IsDefined<T>>;
|
|
7
|
+
assess: typeof assess;
|
|
8
|
+
assure: typeof assure;
|
|
9
|
+
}
|
|
1
10
|
/**
|
|
2
11
|
* checks whether the value is defined and is not null
|
|
3
12
|
*
|
|
4
|
-
*
|
|
13
|
+
* refs
|
|
14
|
+
* - https://github.com/microsoft/TypeScript/issues/16069#issuecomment-566222173
|
|
5
15
|
*/
|
|
6
|
-
|
|
16
|
+
declare const isPresentWithAssure: IsPresentWithAssure;
|
|
17
|
+
export { isPresentWithAssure as isPresent };
|
package/dist/checks/isPresent.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isPresent = void 0;
|
|
4
|
+
const withAssure_1 = require("../wrappers/withAssure");
|
|
5
|
+
const isNotNull_1 = require("./isNotNull");
|
|
6
|
+
const isNotUndefined_1 = require("./isNotUndefined");
|
|
7
|
+
const assess = (t) => (0, isNotNull_1.isNotNull)(t) && (0, isNotUndefined_1.isDefined)(t);
|
|
8
|
+
const assure = (0, withAssure_1.asAssure)(assess, { name: 'isPresent' });
|
|
4
9
|
/**
|
|
5
10
|
* checks whether the value is defined and is not null
|
|
6
11
|
*
|
|
7
|
-
*
|
|
12
|
+
* refs
|
|
13
|
+
* - https://github.com/microsoft/TypeScript/issues/16069#issuecomment-566222173
|
|
8
14
|
*/
|
|
9
|
-
const
|
|
10
|
-
|
|
15
|
+
const isPresentWithAssure = function (...input) {
|
|
16
|
+
return assess(...input);
|
|
17
|
+
};
|
|
18
|
+
exports.isPresent = isPresentWithAssure;
|
|
19
|
+
isPresentWithAssure.assess = assess;
|
|
20
|
+
isPresentWithAssure.assure = assure;
|
|
11
21
|
//# sourceMappingURL=isPresent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPresent.js","sourceRoot":"","sources":["../../src/checks/isPresent.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"isPresent.js","sourceRoot":"","sources":["../../src/checks/isPresent.ts"],"names":[],"mappings":";;;AAAA,uDAAkD;AAClD,2CAAiD;AACjD,qDAAwD;AAExD,MAAM,MAAM,GAAG,CAAI,CAAI,EAA8B,EAAE,CACrD,IAAA,qBAAS,EAAC,CAAC,CAAC,IAAI,IAAA,0BAAS,EAAC,CAAC,CAAC,CAAC;AAC/B,MAAM,MAAM,GAAG,IAAA,qBAAQ,EAAC,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;AAQvD;;;;;GAKG;AACH,MAAM,mBAAmB,GAAwB,UAC/C,GAAG,KAAgC;IAEnC,OAAO,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC;AAC1B,CAGC,CAAC;AAI8B,wCAAS;AAHzC,mBAAmB,CAAC,MAAM,GAAG,MAAM,CAAC;AACpC,mBAAmB,CAAC,MAAM,GAAG,MAAM,CAAC"}
|
|
@@ -1,25 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const test_fns_1 = require("test-fns");
|
|
3
4
|
const isPresent_1 = require("./isPresent");
|
|
4
5
|
describe('isPresent', () => {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
(0, test_fns_1.given)('direct calls should assess by default', () => {
|
|
7
|
+
(0, test_fns_1.when)('called directly', () => {
|
|
8
|
+
(0, test_fns_1.then)('it should return true if is some number, for example', () => {
|
|
9
|
+
const input = 21;
|
|
10
|
+
expect((0, isPresent_1.isPresent)(input)).toEqual(true);
|
|
11
|
+
if (!(0, isPresent_1.isPresent)(input)) {
|
|
12
|
+
const shouldBeNever = input;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
(0, test_fns_1.then)('it should return false if is null', () => {
|
|
16
|
+
const input = null;
|
|
17
|
+
expect((0, isPresent_1.isPresent)(input)).toEqual(false);
|
|
18
|
+
if ((0, isPresent_1.isPresent)(input)) {
|
|
19
|
+
const shouldBeNever = input;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
(0, test_fns_1.then)('it should return false if is undefined', () => {
|
|
23
|
+
const input = undefined;
|
|
24
|
+
expect((0, isPresent_1.isPresent)(input)).toEqual(false);
|
|
25
|
+
if ((0, isPresent_1.isPresent)(input)) {
|
|
26
|
+
const shouldBeNever = input;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
(0, test_fns_1.then)('it should return true if is falsy', () => {
|
|
30
|
+
expect((0, isPresent_1.isPresent)(false)).toEqual(true);
|
|
31
|
+
expect((0, isPresent_1.isPresent)(0)).toEqual(true);
|
|
32
|
+
expect((0, isPresent_1.isPresent)('')).toEqual(true);
|
|
33
|
+
});
|
|
34
|
+
(0, test_fns_1.then)('it should be useful in having correct types after filtering', () => {
|
|
35
|
+
const stringsOrNulls = ['hello', '', null, 'world', undefined]; // type = `(string | null | undefined)[]`
|
|
36
|
+
const strings = stringsOrNulls.filter(isPresent_1.isPresent); // type = string[]
|
|
37
|
+
// check that it did what we expected in runtime
|
|
38
|
+
expect(strings).toEqual(['hello', '', 'world']);
|
|
39
|
+
// check that it successfully informed typescript of this too
|
|
40
|
+
strings.map((string) => string.toUpperCase()); // This should not throw a type error, because the filter should have told typescript it took out the nulls
|
|
41
|
+
});
|
|
42
|
+
});
|
|
7
43
|
});
|
|
8
|
-
|
|
9
|
-
|
|
44
|
+
(0, test_fns_1.given)('it has an assess', () => {
|
|
45
|
+
(0, test_fns_1.when)('.assess is called', () => {
|
|
46
|
+
(0, test_fns_1.then)('it should assess correctly', () => {
|
|
47
|
+
expect(isPresent_1.isPresent.assess(21)).toEqual(true);
|
|
48
|
+
expect(isPresent_1.isPresent.assess(null)).toEqual(false);
|
|
49
|
+
expect(isPresent_1.isPresent.assess(undefined)).toEqual(false);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
10
52
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
53
|
+
(0, test_fns_1.given)('it has an assure', () => {
|
|
54
|
+
(0, test_fns_1.when)('.assure is called', () => {
|
|
55
|
+
(0, test_fns_1.then)('it should assure correctly, for a number, for example', () => {
|
|
56
|
+
const input = 21;
|
|
57
|
+
const shouldWork = isPresent_1.isPresent.assure(input);
|
|
58
|
+
// @ts-expect-error // input could be null or undefined
|
|
59
|
+
const shouldFail = input;
|
|
60
|
+
});
|
|
61
|
+
(0, test_fns_1.then)('it should assure correctly, for null', () => {
|
|
62
|
+
const input = null;
|
|
63
|
+
const error = (0, test_fns_1.getError)(() => {
|
|
64
|
+
const shouldWork = isPresent_1.isPresent.assure(input);
|
|
65
|
+
});
|
|
66
|
+
expect(error.message).toContain(`assure.rejection: input does not satisfy type.check 'isPresent'`);
|
|
67
|
+
});
|
|
68
|
+
(0, test_fns_1.then)('it should assure correctly, for undefined', () => {
|
|
69
|
+
const input = undefined;
|
|
70
|
+
const error = (0, test_fns_1.getError)(() => {
|
|
71
|
+
const shouldWork = isPresent_1.isPresent.assure(input);
|
|
72
|
+
});
|
|
73
|
+
expect(error.message).toContain(`assure.rejection: input does not satisfy type.check 'isPresent'`);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
23
76
|
});
|
|
24
77
|
});
|
|
25
78
|
//# sourceMappingURL=isPresent.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPresent.test.js","sourceRoot":"","sources":["../../src/checks/isPresent.test.ts"],"names":[],"mappings":";;AAAA,2CAAwC;AAExC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,
|
|
1
|
+
{"version":3,"file":"isPresent.test.js","sourceRoot":"","sources":["../../src/checks/isPresent.test.ts"],"names":[],"mappings":";;AAAA,uCAAuD;AAEvD,2CAAwC;AAExC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAA,gBAAK,EAAC,uCAAuC,EAAE,GAAG,EAAE;QAClD,IAAA,eAAI,EAAC,iBAAiB,EAAE,GAAG,EAAE;YAC3B,IAAA,eAAI,EAAC,sDAAsD,EAAE,GAAG,EAAE;gBAChE,MAAM,KAAK,GAAkB,EAAE,CAAC;gBAEhC,MAAM,CAAC,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBAEvC,IAAI,CAAC,IAAA,qBAAS,EAAC,KAAK,CAAC,EAAE,CAAC;oBACtB,MAAM,aAAa,GAAU,KAAK,CAAC;gBACrC,CAAC;YACH,CAAC,CAAC,CAAC;YACH,IAAA,eAAI,EAAC,mCAAmC,EAAE,GAAG,EAAE;gBAC7C,MAAM,KAAK,GAAkB,IAAI,CAAC;gBAElC,MAAM,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AAU,GAAW,qBAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACrD,CAAC,CAAC,CAAC;gBACH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,SAAS,CAC7B,iEAAiE,CAClE,CAAC;YACJ,CAAC,CAAC,CAAC;YACH,IAAA,eAAI,EAAC,2CAA2C,EAAE,GAAG,EAAE;gBACrD,MAAM,KAAK,GAA8B,SAAgB,CAAC;gBAE1D,MAAM,KAAK,GAAG,IAAA,mBAAQ,EAAC,GAAG,EAAE;oBAC1B,MAAM,UAAU,GAAW,qBAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACrD,CAAC,CAAC,CAAC;gBACH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,SAAS,CAC7B,iEAAiE,CAClE,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -28,4 +28,6 @@ __exportStar(require("./checks/isNotUndefined"), exports);
|
|
|
28
28
|
__exportStar(require("./types/DropFirst"), exports);
|
|
29
29
|
__exportStar(require("./companions/omit"), exports);
|
|
30
30
|
__exportStar(require("./companions/pick"), exports);
|
|
31
|
+
__exportStar(require("./types/Literalize"), exports);
|
|
32
|
+
__exportStar(require("./wrappers/withAssure"), exports);
|
|
31
33
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,mDAAiC;AACjC,uDAAqC;AACrC,qDAAmC;AACnC,oDAAkC;AAClC,qDAAmC;AACnC,uDAAqC;AACrC,sDAAoC;AACpC,kDAAgC;AAChC,qDAAmC;AACnC,0DAAwC;AACxC,oDAAkC;AAClC,oDAAkC;AAClC,oDAAkC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,mDAAiC;AACjC,uDAAqC;AACrC,qDAAmC;AACnC,oDAAkC;AAClC,qDAAmC;AACnC,uDAAqC;AACrC,sDAAoC;AACpC,kDAAgC;AAChC,qDAAmC;AACnC,0DAAwC;AACxC,oDAAkC;AAClC,oDAAkC;AAClC,oDAAkC;AAClC,qDAAmC;AACnC,wDAAsC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* expands the type of an enum to include the literal union of its types
|
|
3
|
+
*
|
|
4
|
+
* usecase
|
|
5
|
+
* - when you want to use literals for devexp
|
|
6
|
+
* - yet also want the advantages of enums (semantic purpose; tsdocs on hover; etc)
|
|
7
|
+
*
|
|
8
|
+
* example
|
|
9
|
+
* ```ts
|
|
10
|
+
* enum Berry {
|
|
11
|
+
* RASPBERRY = 'raspberry',
|
|
12
|
+
* STRAWBERRY = 'strawberry',
|
|
13
|
+
* BLUEBERRY = 'blueberry',
|
|
14
|
+
* }
|
|
15
|
+
* const before: Berry = 'raspberry'; // 🛑 Type '"raspberry"' is not assignable to type 'Berries'.ts(2322)
|
|
16
|
+
* const after: Literalize<Berry> = 'raspberry';
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* ref
|
|
20
|
+
* - https://stackoverflow.com/questions/52393730/typescript-string-literal-union-type-from-enum
|
|
21
|
+
*
|
|
22
|
+
* def
|
|
23
|
+
* - "literalize" = interpret or represent literally
|
|
24
|
+
*/
|
|
25
|
+
export type Literalize<T extends string | number | bigint | boolean | null | undefined> = `${T}` | T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Literalize.js","sourceRoot":"","sources":["../../src/types/Literalize.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
describe('Literalize', () => {
|
|
4
|
+
it('should be able to cast enum into union of literals or enum values', () => {
|
|
5
|
+
let Berry;
|
|
6
|
+
(function (Berry) {
|
|
7
|
+
Berry["RASPBERRY"] = "raspberry";
|
|
8
|
+
Berry["STRAWBERRY"] = "strawberry";
|
|
9
|
+
Berry["BLUEBERRY"] = "blueberry";
|
|
10
|
+
})(Berry || (Berry = {}));
|
|
11
|
+
// @ts-expect-error // 🛑 Type '"raspberry"' is not assignable to type 'Berries'.ts(2322)
|
|
12
|
+
const before = 'raspberry';
|
|
13
|
+
// after
|
|
14
|
+
const literally = 'raspberry';
|
|
15
|
+
const originally = Berry.STRAWBERRY;
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=Literalize.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Literalize.test.js","sourceRoot":"","sources":["../../src/types/Literalize.test.ts"],"names":[],"mappings":";;AAEA,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,mEAAmE,EAAE,GAAG,EAAE;QAC3E,IAAK,KAIJ;QAJD,WAAK,KAAK;YACR,gCAAuB,CAAA;YACvB,kCAAyB,CAAA;YACzB,gCAAuB,CAAA;QACzB,CAAC,EAJI,KAAK,KAAL,KAAK,QAIT;QAID,yFAAyF;QACzF,MAAM,MAAM,GAAU,WAAW,CAAC;QAElC,QAAQ;QACR,MAAM,SAAS,GAAa,WAAW,CAAC;QACxC,MAAM,UAAU,GAAa,KAAK,CAAC,UAAU,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
describe('PickOne', () => {
|
|
13
13
|
it('should constrain type correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
-
const findWrench = (
|
|
14
|
+
const findWrench = (_a) => __awaiter(void 0, [_a], void 0, function* ({}) {
|
|
15
15
|
// ...
|
|
16
16
|
});
|
|
17
17
|
// you can find by metric
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PickOne.test.js","sourceRoot":"","sources":["../../src/types/PickOne.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,iCAAiC,EAAE,GAAS,EAAE;QAC/C,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"PickOne.test.js","sourceRoot":"","sources":["../../src/types/PickOne.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,iCAAiC,EAAE,GAAS,EAAE;QAC/C,MAAM,UAAU,GAAG,KAehB,EAAE,4CAfqB,EAezB;YACC,MAAM;QACR,CAAC,CAAA,CAAC;QAEF,yBAAyB;QACzB,MAAM,UAAU,CAAC;YACf,IAAI,EAAE;gBACJ,MAAM,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE;aAC5B;SACF,CAAC,CAAC;QAEH,2BAA2B;QAC3B,MAAM,UAAU,CAAC;YACf,IAAI,EAAE;gBACJ,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;aAC7B;SACF,CAAC,CAAC;QAEH,yBAAyB;QACzB,qBAAqB;QACrB,YAAY;QACZ,mCAAmC;QACnC,oCAAoC;QACpC,OAAO;QACP,MAAM;IACR,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -6,7 +6,7 @@ var Stage;
|
|
|
6
6
|
Stage["PRODUCTION"] = "prod";
|
|
7
7
|
Stage["DEVELOPMENT"] = "dev";
|
|
8
8
|
Stage["TEST"] = "test";
|
|
9
|
-
})(Stage
|
|
9
|
+
})(Stage || (exports.Stage = Stage = {}));
|
|
10
10
|
/**
|
|
11
11
|
* this allows us to infer what the stage should be in environments that do not have STAGE specified
|
|
12
12
|
* - e.g., when running locally
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":";;;AAAA,IAAY,KAIX;AAJD,WAAY,KAAK;IACf,4BAAmB,CAAA;IACnB,4BAAmB,CAAA;IACnB,sBAAa,CAAA;AACf,CAAC,EAJW,KAAK,
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":";;;AAAA,IAAY,KAIX;AAJD,WAAY,KAAK;IACf,4BAAmB,CAAA;IACnB,4BAAmB,CAAA;IACnB,sBAAa,CAAA;AACf,CAAC,EAJW,KAAK,qBAAL,KAAK,QAIhB;AAED;;;;GAIG;AACH,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACjC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,iCAAiC;IACvE,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACtE,IAAI,OAAO,KAAK,YAAY;QAAE,OAAO,KAAK,CAAC,UAAU,CAAC;IACtD,IAAI,OAAO,KAAK,aAAa;QAAE,OAAO,KAAK,CAAC,WAAW,CAAC;IACxD,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC;IAC1C,MAAM,IAAI,KAAK,CAAC,uBAAuB,OAAO,GAAG,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,cAAc,GAAG,GAAG,EAAE;;IAC1B,MAAM,KAAK,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,KAAK,mCAAI,qBAAqB,EAAE,CAAC,CAAC,wDAAwD;IACpH,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACjE,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC,CAAC;AAEF,qDAAqD;AACtC,aAAK,GAAK,cAAc,EAAE,OAAC;AAE1C,8BAA8B;AACjB,QAAA,kBAAkB,GAC7B,aAAK,KAAK,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,8CAA8C"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { HelpfulError } from '@ehmpathy/error-fns';
|
|
2
|
+
export type AssessIsOfTypeMethod<I, C extends I> = (input: I) => input is C;
|
|
3
|
+
export type AssureIsOfTypeMethod<I, C extends I> = (input: I) => C;
|
|
4
|
+
export interface AssessWithAssure<I, C extends I> {
|
|
5
|
+
(input: I): input is C;
|
|
6
|
+
assess: AssessIsOfTypeMethod<I, C>;
|
|
7
|
+
assure: AssureIsOfTypeMethod<I, C>;
|
|
8
|
+
}
|
|
9
|
+
export declare class AssureIsOfTypeRejectionError extends HelpfulError {
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* what: a wrapper which takes a boolean type.check and converts it into a type.assure
|
|
13
|
+
* what^2:
|
|
14
|
+
* - a type.check uses typescript's type.predicate capacity to narrow a type via boolean (i.e., `input is T`)
|
|
15
|
+
* - a type.assure uses this type.check and throws an error if the result was false, assuring that if a result is returned, it is of the desired type
|
|
16
|
+
* why:
|
|
17
|
+
* - makes it easy to fail fast if expectations are not met
|
|
18
|
+
* - simplifies code by rejecting code paths that should not happen, allowing focus on only the expected code paths, rather than having 'if/then' statements all over the place
|
|
19
|
+
* why^2:
|
|
20
|
+
* - simplicity++ -> readability++ -> speed++ && maintainability++
|
|
21
|
+
*/
|
|
22
|
+
export declare const asAssure: <I, C extends I>(assess: AssessIsOfTypeMethod<I, C>, options?: {
|
|
23
|
+
name: string;
|
|
24
|
+
}) => AssureIsOfTypeMethod<I, C>;
|
|
25
|
+
/**
|
|
26
|
+
* what: a wrapper which takes a type.check and adds an .assure and .assess to it
|
|
27
|
+
* what^2:
|
|
28
|
+
* - a type.check uses typescript's type.predicate capacity to narrow a type via boolean (i.e., `input is T`)
|
|
29
|
+
* - a type.assure uses this type.check and throws an error if the result was false, assuring that if a result is returned, it is of the desired type
|
|
30
|
+
* - an .assure and .assess can be added to a function, enabling backwards compatible default .assess usage while still exposing explicit .assure and .assess utilities
|
|
31
|
+
* why:
|
|
32
|
+
* - makes it easy to extend type.checks w/ .assure in a backwards compatible way
|
|
33
|
+
* - enables convenient custom utilities to fail fast if expectations are not met
|
|
34
|
+
* why^2:
|
|
35
|
+
* - simplicity++ -> readability++ -> speed++ && maintainability++
|
|
36
|
+
*
|
|
37
|
+
* note
|
|
38
|
+
* - leverages `asAssure` under the hood
|
|
39
|
+
*/
|
|
40
|
+
export declare const withAssure: <I, C extends I>(assess: AssessIsOfTypeMethod<I, C>, options?: {
|
|
41
|
+
name: string;
|
|
42
|
+
}) => AssessWithAssure<I, C>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withAssure = exports.asAssure = exports.AssureIsOfTypeRejectionError = void 0;
|
|
4
|
+
const error_fns_1 = require("@ehmpathy/error-fns");
|
|
5
|
+
class AssureIsOfTypeRejectionError extends error_fns_1.HelpfulError {
|
|
6
|
+
}
|
|
7
|
+
exports.AssureIsOfTypeRejectionError = AssureIsOfTypeRejectionError;
|
|
8
|
+
/**
|
|
9
|
+
* what: a wrapper which takes a boolean type.check and converts it into a type.assure
|
|
10
|
+
* what^2:
|
|
11
|
+
* - a type.check uses typescript's type.predicate capacity to narrow a type via boolean (i.e., `input is T`)
|
|
12
|
+
* - a type.assure uses this type.check and throws an error if the result was false, assuring that if a result is returned, it is of the desired type
|
|
13
|
+
* why:
|
|
14
|
+
* - makes it easy to fail fast if expectations are not met
|
|
15
|
+
* - simplifies code by rejecting code paths that should not happen, allowing focus on only the expected code paths, rather than having 'if/then' statements all over the place
|
|
16
|
+
* why^2:
|
|
17
|
+
* - simplicity++ -> readability++ -> speed++ && maintainability++
|
|
18
|
+
*/
|
|
19
|
+
const asAssure = (assess, options) => {
|
|
20
|
+
var _a;
|
|
21
|
+
const name = (_a = options === null || options === void 0 ? void 0 : options.name) !== null && _a !== void 0 ? _a : assess.name; // todo: get resource name more reliably
|
|
22
|
+
const assure = (input) => assess(input)
|
|
23
|
+
? input
|
|
24
|
+
: (() => {
|
|
25
|
+
throw new AssureIsOfTypeRejectionError(`assure.rejection: input does not satisfy type.check '${name}'`, {
|
|
26
|
+
check: name,
|
|
27
|
+
input: input === undefined ? 'undefined' : input,
|
|
28
|
+
});
|
|
29
|
+
})();
|
|
30
|
+
return assure;
|
|
31
|
+
};
|
|
32
|
+
exports.asAssure = asAssure;
|
|
33
|
+
/**
|
|
34
|
+
* what: a wrapper which takes a type.check and adds an .assure and .assess to it
|
|
35
|
+
* what^2:
|
|
36
|
+
* - a type.check uses typescript's type.predicate capacity to narrow a type via boolean (i.e., `input is T`)
|
|
37
|
+
* - a type.assure uses this type.check and throws an error if the result was false, assuring that if a result is returned, it is of the desired type
|
|
38
|
+
* - an .assure and .assess can be added to a function, enabling backwards compatible default .assess usage while still exposing explicit .assure and .assess utilities
|
|
39
|
+
* why:
|
|
40
|
+
* - makes it easy to extend type.checks w/ .assure in a backwards compatible way
|
|
41
|
+
* - enables convenient custom utilities to fail fast if expectations are not met
|
|
42
|
+
* why^2:
|
|
43
|
+
* - simplicity++ -> readability++ -> speed++ && maintainability++
|
|
44
|
+
*
|
|
45
|
+
* note
|
|
46
|
+
* - leverages `asAssure` under the hood
|
|
47
|
+
*/
|
|
48
|
+
const withAssure = (assess, options) => {
|
|
49
|
+
const assure = (0, exports.asAssure)(assess, options);
|
|
50
|
+
const result = function (...input) {
|
|
51
|
+
return assess(...input);
|
|
52
|
+
};
|
|
53
|
+
result.assess = assess;
|
|
54
|
+
result.assure = assure;
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
exports.withAssure = withAssure;
|
|
58
|
+
//# sourceMappingURL=withAssure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAssure.js","sourceRoot":"","sources":["../../src/wrappers/withAssure.ts"],"names":[],"mappings":";;;AAAA,mDAAmD;AAUnD,MAAa,4BAA6B,SAAQ,wBAAY;CAAG;AAAjE,oEAAiE;AAEjE;;;;;;;;;;GAUG;AACI,MAAM,QAAQ,GAAG,CACtB,MAAkC,EAClC,OAA0B,EACE,EAAE;;IAC9B,MAAM,IAAI,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,mCAAI,MAAM,CAAC,IAAI,CAAC,CAAC,wCAAwC;IACnF,MAAM,MAAM,GAAG,CAAC,KAAQ,EAAE,EAAE,CAC1B,MAAM,CAAC,KAAK,CAAC;QACX,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,CAAC,GAAG,EAAE;YACJ,MAAM,IAAI,4BAA4B,CACpC,wDAAwD,IAAI,GAAG,EAC/D;gBACE,KAAK,EAAE,IAAI;gBACX,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK;aACjD,CACF,CAAC;QACJ,CAAC,CAAC,EAAE,CAAC;IACX,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAlBW,QAAA,QAAQ,YAkBnB;AAEF;;;;;;;;;;;;;;GAcG;AACI,MAAM,UAAU,GAAG,CACxB,MAAkC,EAClC,OAA0B,EACF,EAAE;IAC1B,MAAM,MAAM,GAAG,IAAA,gBAAQ,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,UACb,GAAG,KAAgC;QAEnC,OAAO,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC;IAC1B,CAGC,CAAC;IACF,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAhBW,QAAA,UAAU,cAgBrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const test_fns_1 = require("test-fns");
|
|
4
|
+
const withAssure_1 = require("./withAssure");
|
|
5
|
+
describe('asAssure', () => {
|
|
6
|
+
it('should be able to assure for a specific check', () => {
|
|
7
|
+
const isAString = (input) => typeof input === 'string';
|
|
8
|
+
const assure = (0, withAssure_1.asAssure)(isAString);
|
|
9
|
+
const shouldBeString = assure('hi');
|
|
10
|
+
const error = (0, test_fns_1.getError)(() => {
|
|
11
|
+
const shouldThrowBeforeHere = assure(7);
|
|
12
|
+
});
|
|
13
|
+
expect(error.message).toContain(`input does not satisfy type.check 'isAString'`);
|
|
14
|
+
});
|
|
15
|
+
it('should be able to assure for a generic check', () => {
|
|
16
|
+
const isNotNull = (input) => input !== null;
|
|
17
|
+
const assure = (0, withAssure_1.asAssure)(isNotNull);
|
|
18
|
+
const shouldBeString = assure('hi');
|
|
19
|
+
const shouldBeNumber = assure(7);
|
|
20
|
+
const error = (0, test_fns_1.getError)(() => {
|
|
21
|
+
const shouldThrowBeforeHere = assure(null);
|
|
22
|
+
});
|
|
23
|
+
expect(error.message).toContain(`input does not satisfy type.check 'isNotNull'`);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
describe('withAssure', () => {
|
|
27
|
+
it('should be able to add assure to a specific check', () => {
|
|
28
|
+
const isAString = (0, withAssure_1.withAssure)((input) => typeof input === 'string', { name: 'isAString' });
|
|
29
|
+
const shouldBeString = isAString.assure('hi');
|
|
30
|
+
const error = (0, test_fns_1.getError)(() => {
|
|
31
|
+
const shouldThrowBeforeHere = isAString.assure(7);
|
|
32
|
+
});
|
|
33
|
+
expect(error.message).toContain(`input does not satisfy type.check 'isAString'`);
|
|
34
|
+
});
|
|
35
|
+
it.skip('should be able to assure for a generic check', () => {
|
|
36
|
+
const isNotNullOrig = (input) => input !== null;
|
|
37
|
+
const isNotNull = (0, withAssure_1.withAssure)(isNotNullOrig);
|
|
38
|
+
// @ts-expect-error // todo: fix this once typescript enables passing through generic types. (today for generic, ReturnType<AssureMethod> works but ReturnType<{ assure: AssureMethod }> does not, leading this to fail)
|
|
39
|
+
const shouldBeString = isNotNull.assure('hi');
|
|
40
|
+
// @ts-expect-error // todo: fix this once typescript enables passing through generic types. (today for generic, ReturnType<AssureMethod> works but ReturnType<{ assure: AssureMethod }> does not, leading this to fail)
|
|
41
|
+
const shouldBeNumber = isNotNull.assure(7);
|
|
42
|
+
const error = (0, test_fns_1.getError)(() => {
|
|
43
|
+
// @ts-expect-error // todo: fix this once typescript enables passing through generic types. (today for generic, ReturnType<AssureMethod> works but ReturnType<{ assure: AssureMethod }> does not, leading this to fail)
|
|
44
|
+
const shouldThrowBeforeHere = isNotNull.assure(null);
|
|
45
|
+
});
|
|
46
|
+
expect(error.message).toContain(`input does not satisfy type.check 'isNotNull'`);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=withAssure.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAssure.test.js","sourceRoot":"","sources":["../../src/wrappers/withAssure.test.ts"],"names":[],"mappings":";;AAAA,uCAAoC;AAGpC,6CAAoD;AAEpD,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,SAAS,GAAG,CAAC,KAAU,EAAmB,EAAE,CAChD,OAAO,KAAK,KAAK,QAAQ,CAAC;QAE5B,MAAM,MAAM,GAAG,IAAA,qBAAQ,EAAC,SAAS,CAAC,CAAC;QAE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MAAM,qBAAqB,GAAW,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,SAAS,CAC7B,+CAA+C,CAChD,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,IAAI,CAAC,8CAA8C,EAAE,GAAG,EAAE;QAC3D,MAAM,aAAa,GAAG,CAAI,KAAQ,EAAuB,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC;QAC3E,MAAM,SAAS,GAAG,IAAA,uBAAU,EAAC,aAAa,CAAC,CAAC;QAE5C,wNAAwN;QACxN,MAAM,cAAc,GAAW,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,wNAAwN;QACxN,MAAM,cAAc,GAAW,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAEnD,MAAM,KAAK,GAAG,IAAA,mBAAQ,EAAC,GAAG,EAAE;YAC1B,wNAAwN;YACxN,MAAM,qBAAqB,GAAU,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,SAAS,CAC7B,+CAA+C,CAChD,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "type-fns",
|
|
3
3
|
"author": "ehmpathy",
|
|
4
4
|
"description": "A set of types, type checks, and type guards for simpler, safer, and easier to read code.",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "1.13.0",
|
|
6
6
|
"repository": "ehmpathy/type-fns",
|
|
7
7
|
"homepage": "https://github.com/ehmpathy/type-fns",
|
|
8
8
|
"keywords": [
|
|
@@ -56,29 +56,33 @@
|
|
|
56
56
|
"@tsconfig/node-lts-strictest": "18.12.1",
|
|
57
57
|
"@types/jest": "29.2.4",
|
|
58
58
|
"@types/uuid": "9.0.0",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "
|
|
60
|
-
"@typescript-eslint/parser": "
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "7.8.0",
|
|
60
|
+
"@typescript-eslint/parser": "7.8.0",
|
|
61
61
|
"core-js": "3.26.1",
|
|
62
62
|
"cz-conventional-changelog": "3.3.0",
|
|
63
63
|
"declapract": "0.11.2",
|
|
64
64
|
"declapract-typescript-ehmpathy": "0.23.7",
|
|
65
65
|
"depcheck": "1.4.3",
|
|
66
|
-
"eslint": "8.
|
|
67
|
-
"eslint-config-airbnb-typescript": "
|
|
66
|
+
"eslint": "8.56.0",
|
|
67
|
+
"eslint-config-airbnb-typescript": "18.0.0",
|
|
68
68
|
"eslint-config-prettier": "8.5.0",
|
|
69
69
|
"eslint-plugin-import": "2.26.0",
|
|
70
70
|
"eslint-plugin-prettier": "4.2.1",
|
|
71
71
|
"husky": "7.0.2",
|
|
72
72
|
"jest": "29.3.1",
|
|
73
73
|
"prettier": "2.8.1",
|
|
74
|
+
"test-fns": "1.3.0",
|
|
74
75
|
"ts-jest": "29.0.3",
|
|
75
|
-
"ts-node": "10.9.
|
|
76
|
-
"typescript": "4.
|
|
76
|
+
"ts-node": "10.9.2",
|
|
77
|
+
"typescript": "5.4.5",
|
|
77
78
|
"uuid": "^3.3.3"
|
|
78
79
|
},
|
|
79
80
|
"config": {
|
|
80
81
|
"commitizen": {
|
|
81
82
|
"path": "./node_modules/cz-conventional-changelog"
|
|
82
83
|
}
|
|
84
|
+
},
|
|
85
|
+
"dependencies": {
|
|
86
|
+
"@ehmpathy/error-fns": "1.0.2"
|
|
83
87
|
}
|
|
84
88
|
}
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NotUndefined.js","sourceRoot":"","sources":["../../src/types/NotUndefined.ts"],"names":[],"mappings":""}
|