ts-type-predicates 1.0.7 → 1.0.9
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/CHANGELOG.md +26 -0
- package/dist/index.cjs.development.cjs +10 -9
- package/dist/index.cjs.development.cjs.map +1 -1
- package/dist/index.cjs.production.min.cjs +1 -1
- package/dist/index.cjs.production.min.cjs.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.esm.mjs +14 -11
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.umd.development.cjs +10 -9
- package/dist/index.umd.development.cjs.map +1 -1
- package/dist/index.umd.production.min.cjs +1 -1
- package/dist/index.umd.production.min.cjs.map +1 -1
- package/package.json +9 -8
- package/src/index.js.map +1 -1
- package/src/index.ts +48 -0
- package/src/index.d.ts +0 -9
- package/src/index.js +0 -37
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,32 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.0.9](https://github.com/bluelovers/ws-ts-type/compare/ts-type-predicates@1.0.8...ts-type-predicates@1.0.9) (2022-10-10)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### 📌 Dependencies
|
|
11
|
+
|
|
12
|
+
* update deps ([ab5f3e4](https://github.com/bluelovers/ws-ts-type/commit/ab5f3e48da1f10ddd4445ba6dda9a0a68c5f656f))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### 🔖 Miscellaneous
|
|
16
|
+
|
|
17
|
+
* . ([9219017](https://github.com/bluelovers/ws-ts-type/commit/92190178fcf30f881c1d0d36fb141a3394ab3b38))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## [1.0.8](https://github.com/bluelovers/ws-ts-type/compare/ts-type-predicates@1.0.7...ts-type-predicates@1.0.8) (2022-08-10)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### 📌 Dependencies
|
|
25
|
+
|
|
26
|
+
* update deps ([50b4a8d](https://github.com/bluelovers/ws-ts-type/commit/50b4a8dab38d41ccf29b194be76f9fb5673f8162))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
6
32
|
## [1.0.7](https://github.com/bluelovers/ws-ts-type/compare/ts-type-predicates@1.0.6...ts-type-predicates@1.0.7) (2022-07-05)
|
|
7
33
|
|
|
8
34
|
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var assert = require('assert');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function _handleExpression(actual, expression = true) {
|
|
8
8
|
var _expression;
|
|
9
9
|
|
|
10
10
|
(_expression = expression) !== null && _expression !== void 0 ? _expression : expression = true;
|
|
@@ -13,22 +13,22 @@ function typePredicates(actual, expression = true, message, ignoreExpression) {
|
|
|
13
13
|
expression = !!expression(actual);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
return expression;
|
|
17
|
+
}
|
|
18
|
+
function typePredicates(actual, expression = true, message, ignoreExpression) {
|
|
19
|
+
expression = _handleExpression(actual, expression);
|
|
20
|
+
|
|
16
21
|
if (expression !== true && ignoreExpression !== true) {
|
|
17
22
|
throw new assert.AssertionError({
|
|
18
23
|
message: message !== null && message !== void 0 ? message : `actual ${actual} not as expected`,
|
|
19
24
|
actual,
|
|
20
|
-
expected: expression
|
|
25
|
+
expected: expression,
|
|
26
|
+
operator: 'typePredicates'
|
|
21
27
|
});
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
30
|
function typeNarrowed(actual, expression = true, message) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
(_expression2 = expression) !== null && _expression2 !== void 0 ? _expression2 : expression = true;
|
|
28
|
-
|
|
29
|
-
if (typeof expression === 'function') {
|
|
30
|
-
expression = !!expression(actual);
|
|
31
|
-
}
|
|
31
|
+
expression = _handleExpression(actual, expression);
|
|
32
32
|
|
|
33
33
|
if (expression !== true) {
|
|
34
34
|
expression = false;
|
|
@@ -37,6 +37,7 @@ function typeNarrowed(actual, expression = true, message) {
|
|
|
37
37
|
return expression;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
exports._handleExpression = _handleExpression;
|
|
40
41
|
exports["default"] = typePredicates;
|
|
41
42
|
exports.typeNarrowed = typeNarrowed;
|
|
42
43
|
exports.typePredicates = typePredicates;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.development.cjs","sources":["../src/index.ts"],"sourcesContent":["import { AssertionError } from 'assert';\n\n/**\n * use asserts for make type predicates work\n *\n * @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions\n */\nexport function typePredicates<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string, ignoreExpression?: boolean): asserts actual is T\n{\n\texpression
|
|
1
|
+
{"version":3,"file":"index.cjs.development.cjs","sources":["../src/index.ts"],"sourcesContent":["import { AssertionError } from 'assert';\n\nexport function _handleExpression<T, P = any>(actual: T | P, expression: boolean | ((actual: T | P) => any) = true)\n{\n\texpression ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\n\n\treturn expression\n}\n\n/**\n * use asserts for make type predicates work\n *\n * @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions\n */\nexport function typePredicates<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string, ignoreExpression?: boolean): asserts actual is T\n{\n\texpression = _handleExpression(actual, expression);\n\n\tif (expression !== true && ignoreExpression !== true)\n\t{\n\t\tthrow new AssertionError({\n\t\t\tmessage: message ?? `actual ${actual} not as expected`,\n\t\t\tactual,\n\t\t\texpected: expression,\n\t\t\toperator: 'typePredicates',\n\t\t})\n\t}\n}\n\nexport function typeNarrowed<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string): actual is T\n{\n\texpression = _handleExpression(actual, expression);\n\n\tif (expression !== true)\n\t{\n\t\texpression = false;\n\t}\n\n\treturn expression\n}\n\nexport default typePredicates;\n"],"names":["expression","message","typeNarrowed","actual"],"mappings":";;;;;;;;;;;EAAA,IAAwC,OAAA,UAAA,KAAA,UAAA,EAAA;cAI7B,eAAU;AAInB,GAAA;;AAGD,EAAA,OAAAA,UAAA,CAAA;;AAWA,SAAA,cAAA,CAAA,MAAA,EAAA,UAAA,GAAA,IAAA,EAAA,OAAA,EAAA,gBAAA,EAAA;YAIC,oBAAU;;AACT,EAAA,IAAA,UAAA,KAAA,IAAA,IAAA,gBAAA,KAAA,IAAA,EAAA;;MAEAC;;;;;AAMG,GAAA;AAEL,CAAA;SAIWC,aAAAC,QAASH,UAAA,SAAAC,SAAA;AAGpBD,EAAAA,UAAA,oBAAiB,CAAjB,MAAA,EAAA,UAAA,CAAA,CAAA;;MAGDA,UAAA,KAAA,IAAA,EAAA;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("assert");function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("assert");function _handleExpression(e,r=!0){var t;return null!==(t=r)&&void 0!==t||(r=!0),"function"==typeof r&&(r=!!r(e)),r}function typePredicates(r,t=!0,s,n){if(!0!==(t=_handleExpression(r,t))&&!0!==n)throw new e.AssertionError({message:null!=s?s:`actual ${r} not as expected`,actual:r,expected:t,operator:"typePredicates"})}exports._handleExpression=_handleExpression,exports.default=typePredicates,exports.typeNarrowed=function typeNarrowed(e,r=!0,t){return!0!==(r=_handleExpression(e,r))&&(r=!1),r},exports.typePredicates=typePredicates;
|
|
2
2
|
//# sourceMappingURL=index.cjs.production.min.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.production.min.cjs","sources":["../src/index.ts"],"sourcesContent":["import { AssertionError } from 'assert';\n\n/**\n * use asserts for make type predicates work\n *\n * @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions\n */\nexport function typePredicates<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string, ignoreExpression?: boolean): asserts actual is T\n{\n\texpression
|
|
1
|
+
{"version":3,"file":"index.cjs.production.min.cjs","sources":["../src/index.ts"],"sourcesContent":["import { AssertionError } from 'assert';\n\nexport function _handleExpression<T, P = any>(actual: T | P, expression: boolean | ((actual: T | P) => any) = true)\n{\n\texpression ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\n\n\treturn expression\n}\n\n/**\n * use asserts for make type predicates work\n *\n * @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions\n */\nexport function typePredicates<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string, ignoreExpression?: boolean): asserts actual is T\n{\n\texpression = _handleExpression(actual, expression);\n\n\tif (expression !== true && ignoreExpression !== true)\n\t{\n\t\tthrow new AssertionError({\n\t\t\tmessage: message ?? `actual ${actual} not as expected`,\n\t\t\tactual,\n\t\t\texpected: expression,\n\t\t\toperator: 'typePredicates',\n\t\t})\n\t}\n}\n\nexport function typeNarrowed<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string): actual is T\n{\n\texpression = _handleExpression(actual, expression);\n\n\tif (expression !== true)\n\t{\n\t\texpression = false;\n\t}\n\n\treturn expression\n}\n\nexport default typePredicates;\n"],"names":["expression","typePredicates","actual","message","ignoreExpression","typeNarrowed"],"mappings":"qIAWC,wCAXuC,mBAAAA,cAWvCA,EAWA,SAAAC,eAAAC,EAAAF,GAAA,EAAAG,EAAAC,GAKE,IAAA,iCAAA,IAAAA,8BAEAD,+FAQF,0GAIWE,aAAAH,EAASF,KAAAG,UAMrB,KAHCH,oBAAAE,EAAAF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare function _handleExpression<T, P = any>(actual: T | P, expression?: boolean | ((actual: T | P) => any)): boolean;
|
|
1
2
|
/**
|
|
2
3
|
* use asserts for make type predicates work
|
|
3
4
|
*
|
|
@@ -6,6 +7,9 @@
|
|
|
6
7
|
*/
|
|
7
8
|
export declare function typePredicates<T, P = any>(actual: T | P, expression?: boolean | ((actual: T | P) => any), message?: string, ignoreExpression?: boolean): asserts actual is T;
|
|
8
9
|
export declare function typeNarrowed<T, P = any>(actual: T | P, expression?: boolean | ((actual: T | P) => any), message?: string): actual is T;
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
typePredicates as default,
|
|
13
|
+
};
|
|
10
14
|
|
|
11
15
|
export {};
|
package/dist/index.esm.mjs
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { AssertionError as e } from "assert";
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
function _handleExpression(e, t = !0) {
|
|
4
|
+
var r;
|
|
5
|
+
return null !== (r = t) && void 0 !== r || (t = !0), "function" == typeof t && (t = !!t(e)),
|
|
6
|
+
t;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function typePredicates(t, r = !0, n, a) {
|
|
10
|
+
if (!0 !== (r = _handleExpression(t, r)) && !0 !== a) throw new e({
|
|
11
|
+
message: null != n ? n : `actual ${t} not as expected`,
|
|
8
12
|
actual: t,
|
|
9
|
-
expected:
|
|
13
|
+
expected: r,
|
|
14
|
+
operator: "typePredicates"
|
|
10
15
|
});
|
|
11
16
|
}
|
|
12
17
|
|
|
13
|
-
function typeNarrowed(e, t = !0,
|
|
14
|
-
|
|
15
|
-
return null !== (r = t) && void 0 !== r || (t = !0), "function" == typeof t && (t = !!t(e)),
|
|
16
|
-
!0 !== t && (t = !1), t;
|
|
18
|
+
function typeNarrowed(e, t = !0, r) {
|
|
19
|
+
return !0 !== (t = _handleExpression(e, t)) && (t = !1), t;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
export { typePredicates as default, typeNarrowed, typePredicates };
|
|
22
|
+
export { _handleExpression, typePredicates as default, typeNarrowed, typePredicates };
|
|
20
23
|
//# sourceMappingURL=index.esm.mjs.map
|
package/dist/index.esm.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.mjs","sources":["../src/index.ts"],"sourcesContent":["import { AssertionError } from 'assert';\n\n/**\n * use asserts for make type predicates work\n *\n * @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions\n */\nexport function typePredicates<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string, ignoreExpression?: boolean): asserts actual is T\n{\n\texpression
|
|
1
|
+
{"version":3,"file":"index.esm.mjs","sources":["../src/index.ts"],"sourcesContent":["import { AssertionError } from 'assert';\n\nexport function _handleExpression<T, P = any>(actual: T | P, expression: boolean | ((actual: T | P) => any) = true)\n{\n\texpression ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\n\n\treturn expression\n}\n\n/**\n * use asserts for make type predicates work\n *\n * @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions\n */\nexport function typePredicates<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string, ignoreExpression?: boolean): asserts actual is T\n{\n\texpression = _handleExpression(actual, expression);\n\n\tif (expression !== true && ignoreExpression !== true)\n\t{\n\t\tthrow new AssertionError({\n\t\t\tmessage: message ?? `actual ${actual} not as expected`,\n\t\t\tactual,\n\t\t\texpected: expression,\n\t\t\toperator: 'typePredicates',\n\t\t})\n\t}\n}\n\nexport function typeNarrowed<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string): actual is T\n{\n\texpression = _handleExpression(actual, expression);\n\n\tif (expression !== true)\n\t{\n\t\texpression = false;\n\t}\n\n\treturn expression\n}\n\nexport default typePredicates;\n"],"names":["expression","typePredicates","actual","message","ignoreExpression","typeNarrowed"],"mappings":";;;;EAWC,qDAXuC,qBAAAA;EAWvCA;;;AAWA,SAAAC,eAAAC,GAAAF,KAAA,GAAAG,GAAAC;EAKE,KAAA,wCAAA,MAAAA;IAEAD;;;;;AAQF;;SAIWE,aAAAH,GAASF,QAAAG;UAMrB,OAHCH,sBAAAE,GAAAF;;;"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TsTypePredicates = {}, global.assert));
|
|
5
5
|
})(this, (function (exports, assert) { 'use strict';
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function _handleExpression(actual, expression = true) {
|
|
8
8
|
var _expression;
|
|
9
9
|
|
|
10
10
|
(_expression = expression) !== null && _expression !== void 0 ? _expression : expression = true;
|
|
@@ -13,22 +13,22 @@
|
|
|
13
13
|
expression = !!expression(actual);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
return expression;
|
|
17
|
+
}
|
|
18
|
+
function typePredicates(actual, expression = true, message, ignoreExpression) {
|
|
19
|
+
expression = _handleExpression(actual, expression);
|
|
20
|
+
|
|
16
21
|
if (expression !== true && ignoreExpression !== true) {
|
|
17
22
|
throw new assert.AssertionError({
|
|
18
23
|
message: message !== null && message !== void 0 ? message : `actual ${actual} not as expected`,
|
|
19
24
|
actual,
|
|
20
|
-
expected: expression
|
|
25
|
+
expected: expression,
|
|
26
|
+
operator: 'typePredicates'
|
|
21
27
|
});
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
30
|
function typeNarrowed(actual, expression = true, message) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
(_expression2 = expression) !== null && _expression2 !== void 0 ? _expression2 : expression = true;
|
|
28
|
-
|
|
29
|
-
if (typeof expression === 'function') {
|
|
30
|
-
expression = !!expression(actual);
|
|
31
|
-
}
|
|
31
|
+
expression = _handleExpression(actual, expression);
|
|
32
32
|
|
|
33
33
|
if (expression !== true) {
|
|
34
34
|
expression = false;
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
return expression;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
exports._handleExpression = _handleExpression;
|
|
40
41
|
exports["default"] = typePredicates;
|
|
41
42
|
exports.typeNarrowed = typeNarrowed;
|
|
42
43
|
exports.typePredicates = typePredicates;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.development.cjs","sources":["../src/index.ts"],"sourcesContent":["import { AssertionError } from 'assert';\n\n/**\n * use asserts for make type predicates work\n *\n * @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions\n */\nexport function typePredicates<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string, ignoreExpression?: boolean): asserts actual is T\n{\n\texpression
|
|
1
|
+
{"version":3,"file":"index.umd.development.cjs","sources":["../src/index.ts"],"sourcesContent":["import { AssertionError } from 'assert';\n\nexport function _handleExpression<T, P = any>(actual: T | P, expression: boolean | ((actual: T | P) => any) = true)\n{\n\texpression ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\n\n\treturn expression\n}\n\n/**\n * use asserts for make type predicates work\n *\n * @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions\n */\nexport function typePredicates<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string, ignoreExpression?: boolean): asserts actual is T\n{\n\texpression = _handleExpression(actual, expression);\n\n\tif (expression !== true && ignoreExpression !== true)\n\t{\n\t\tthrow new AssertionError({\n\t\t\tmessage: message ?? `actual ${actual} not as expected`,\n\t\t\tactual,\n\t\t\texpected: expression,\n\t\t\toperator: 'typePredicates',\n\t\t})\n\t}\n}\n\nexport function typeNarrowed<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string): actual is T\n{\n\texpression = _handleExpression(actual, expression);\n\n\tif (expression !== true)\n\t{\n\t\texpression = false;\n\t}\n\n\treturn expression\n}\n\nexport default typePredicates;\n"],"names":["expression","message","typeNarrowed","actual"],"mappings":";;;;;;;;;;;GAAA,IAAwC,OAAA,UAAA,KAAA,UAAA,EAAA;eAI7B,eAAU;CAInB,GAAA;;CAGD,EAAA,OAAAA,UAAA,CAAA;;CAWA,SAAA,cAAA,CAAA,MAAA,EAAA,UAAA,GAAA,IAAA,EAAA,OAAA,EAAA,gBAAA,EAAA;aAIC,oBAAU;;CACT,EAAA,IAAA,UAAA,KAAA,IAAA,IAAA,gBAAA,KAAA,IAAA,EAAA;;OAEAC;;;;;CAMG,GAAA;CAEL,CAAA;UAIWC,aAAAC,QAASH,UAAA,SAAAC,SAAA;CAGpBD,EAAAA,UAAA,oBAAiB,CAAjB,MAAA,EAAA,UAAA,CAAA,CAAA;;OAGDA,UAAA,KAAA,IAAA,EAAA;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("assert")):"function"==typeof define&&define.amd?define(["exports","assert"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TsTypePredicates={},e.assert)}(this,(function(e,t){"use strict";function
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("assert")):"function"==typeof define&&define.amd?define(["exports","assert"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TsTypePredicates={},e.assert)}(this,(function(e,t){"use strict";function _handleExpression(e,t=!0){var n;return null!==(n=t)&&void 0!==n||(t=!0),"function"==typeof t&&(t=!!t(e)),t}function typePredicates(e,n=!0,r,s){if(!0!==(n=_handleExpression(e,n))&&!0!==s)throw new t.AssertionError({message:null!=r?r:`actual ${e} not as expected`,actual:e,expected:n,operator:"typePredicates"})}e._handleExpression=_handleExpression,e.default=typePredicates,e.typeNarrowed=function typeNarrowed(e,t=!0,n){return!0!==(t=_handleExpression(e,t))&&(t=!1),t},e.typePredicates=typePredicates,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=index.umd.production.min.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.production.min.cjs","sources":["../src/index.ts"],"sourcesContent":["import { AssertionError } from 'assert';\n\n/**\n * use asserts for make type predicates work\n *\n * @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions\n */\nexport function typePredicates<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string, ignoreExpression?: boolean): asserts actual is T\n{\n\texpression
|
|
1
|
+
{"version":3,"file":"index.umd.production.min.cjs","sources":["../src/index.ts"],"sourcesContent":["import { AssertionError } from 'assert';\n\nexport function _handleExpression<T, P = any>(actual: T | P, expression: boolean | ((actual: T | P) => any) = true)\n{\n\texpression ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\n\n\treturn expression\n}\n\n/**\n * use asserts for make type predicates work\n *\n * @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions\n */\nexport function typePredicates<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string, ignoreExpression?: boolean): asserts actual is T\n{\n\texpression = _handleExpression(actual, expression);\n\n\tif (expression !== true && ignoreExpression !== true)\n\t{\n\t\tthrow new AssertionError({\n\t\t\tmessage: message ?? `actual ${actual} not as expected`,\n\t\t\tactual,\n\t\t\texpected: expression,\n\t\t\toperator: 'typePredicates',\n\t\t})\n\t}\n}\n\nexport function typeNarrowed<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string): actual is T\n{\n\texpression = _handleExpression(actual, expression);\n\n\tif (expression !== true)\n\t{\n\t\texpression = false;\n\t}\n\n\treturn expression\n}\n\nexport default typePredicates;\n"],"names":["expression","typePredicates","actual","message","ignoreExpression","typeNarrowed"],"mappings":"uUAWC,wCAXuC,mBAAAA,cAWvCA,EAWA,SAAAC,eAAAC,EAAAF,GAAA,EAAAG,EAAAC,GAKE,IAAA,iCAAA,IAAAA,8BAEAD,+FAQF,wFAIWE,aAAAH,EAASF,KAAAG,UAMrB,KAHCH,oBAAAE,EAAAF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-type-predicates",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "use asserts for make type predicates work",
|
|
5
5
|
"keywords": [
|
|
6
6
|
".d.ts",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"repository": {
|
|
37
37
|
"type": "git",
|
|
38
|
-
"url": "git+https://github.com/bluelovers/ws-ts-type.git"
|
|
38
|
+
"url": "git+https://github.com/bluelovers/ws-ts-type.git",
|
|
39
|
+
"directory": "packages/ts-type-predicates"
|
|
39
40
|
},
|
|
40
41
|
"license": "ISC",
|
|
41
42
|
"author": "bluelovers",
|
|
@@ -44,7 +45,8 @@
|
|
|
44
45
|
"types": "./dist/index.d.ts",
|
|
45
46
|
"import": "./dist/index.esm.mjs",
|
|
46
47
|
"require": "./dist/index.cjs"
|
|
47
|
-
}
|
|
48
|
+
},
|
|
49
|
+
"./package.json": "./package.json"
|
|
48
50
|
},
|
|
49
51
|
"main": "dist/index.cjs",
|
|
50
52
|
"module": "dist/index.esm.mjs",
|
|
@@ -57,7 +59,10 @@
|
|
|
57
59
|
"lint": "ynpx --quiet eslint -- **/*.ts",
|
|
58
60
|
"test": "echo \"Error: no test specified\"",
|
|
59
61
|
"test:jest": "ynpx --quiet jest -- --coverage",
|
|
62
|
+
"test:jest:snapshot": "yarn run test:jest -- -u",
|
|
60
63
|
"test:mocha": "ynpx --quiet -p ts-node -p mocha mocha -- --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"",
|
|
64
|
+
"test:snapshot": "yarn run test -- -u",
|
|
65
|
+
"test:tsd": "ynpx tsd",
|
|
61
66
|
"posttest": "yarn run build",
|
|
62
67
|
"build": "yarn run build:tsdx && yarn run build:dts",
|
|
63
68
|
"build:dts": "ynpx dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts --no-banner & echo build:dts",
|
|
@@ -77,10 +82,6 @@
|
|
|
77
82
|
"sort-package-json": "ynpx --quiet yarn-tool -- sort",
|
|
78
83
|
"tsc:showConfig": "ynpx get-current-tsconfig -p"
|
|
79
84
|
},
|
|
80
|
-
"devDependencies": {
|
|
81
|
-
"@bluelovers/tsconfig": "*",
|
|
82
|
-
"@types/node": "*"
|
|
83
|
-
},
|
|
84
85
|
"packageManager": "yarn@^1.22.11",
|
|
85
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "fa34eea119b9bcbb363061ddffcfe9d78c2d0ddd"
|
|
86
87
|
}
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,mCAAwC;AAExC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,mCAAwC;AAExC,SAAgB,iBAAiB,CAAa,MAAa,EAAE,aAAiD,IAAI;IAEjH,UAAU,aAAV,UAAU,cAAV,UAAU,IAAV,UAAU,GAAK,IAAI,EAAC;IAEpB,IAAI,OAAO,UAAU,KAAK,UAAU,EACpC;QACC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;KAClC;IAED,OAAO,UAAU,CAAA;AAClB,CAAC;AAVD,8CAUC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAa,MAAa,EAAE,aAAkD,IAAI,EAAE,OAAgB,EAAE,gBAA0B;IAE7J,UAAU,GAAG,iBAAiB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAEnD,IAAI,UAAU,KAAK,IAAI,IAAI,gBAAgB,KAAK,IAAI,EACpD;QACC,MAAM,IAAI,uBAAc,CAAC;YACxB,OAAO,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,UAAU,MAAM,kBAAkB;YACtD,MAAM;YACN,QAAQ,EAAE,UAAU;YACpB,QAAQ,EAAE,gBAAgB;SAC1B,CAAC,CAAA;KACF;AACF,CAAC;AAbD,wCAaC;AAED,SAAgB,YAAY,CAAa,MAAa,EAAE,aAAkD,IAAI,EAAE,OAAgB;IAE/H,UAAU,GAAG,iBAAiB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAEnD,IAAI,UAAU,KAAK,IAAI,EACvB;QACC,UAAU,GAAG,KAAK,CAAC;KACnB;IAED,OAAO,UAAU,CAAA;AAClB,CAAC;AAVD,oCAUC;AAED,kBAAe,cAAc,CAAC","sourcesContent":["import { AssertionError } from 'assert';\n\nexport function _handleExpression<T, P = any>(actual: T | P, expression: boolean | ((actual: T | P) => any) = true)\n{\n\texpression ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\n\n\treturn expression\n}\n\n/**\n * use asserts for make type predicates work\n *\n * @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions\n */\nexport function typePredicates<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string, ignoreExpression?: boolean): asserts actual is T\n{\n\texpression = _handleExpression(actual, expression);\n\n\tif (expression !== true && ignoreExpression !== true)\n\t{\n\t\tthrow new AssertionError({\n\t\t\tmessage: message ?? `actual ${actual} not as expected`,\n\t\t\tactual,\n\t\t\texpected: expression,\n\t\t\toperator: 'typePredicates',\n\t\t})\n\t}\n}\n\nexport function typeNarrowed<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string): actual is T\n{\n\texpression = _handleExpression(actual, expression);\n\n\tif (expression !== true)\n\t{\n\t\texpression = false;\n\t}\n\n\treturn expression\n}\n\nexport default typePredicates;\n"]}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AssertionError } from 'assert';
|
|
2
|
+
|
|
3
|
+
export function _handleExpression<T, P = any>(actual: T | P, expression: boolean | ((actual: T | P) => any) = true)
|
|
4
|
+
{
|
|
5
|
+
expression ??= true;
|
|
6
|
+
|
|
7
|
+
if (typeof expression === 'function')
|
|
8
|
+
{
|
|
9
|
+
expression = !!expression(actual);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return expression
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* use asserts for make type predicates work
|
|
17
|
+
*
|
|
18
|
+
* @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates
|
|
19
|
+
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
|
|
20
|
+
*/
|
|
21
|
+
export function typePredicates<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string, ignoreExpression?: boolean): asserts actual is T
|
|
22
|
+
{
|
|
23
|
+
expression = _handleExpression(actual, expression);
|
|
24
|
+
|
|
25
|
+
if (expression !== true && ignoreExpression !== true)
|
|
26
|
+
{
|
|
27
|
+
throw new AssertionError({
|
|
28
|
+
message: message ?? `actual ${actual} not as expected`,
|
|
29
|
+
actual,
|
|
30
|
+
expected: expression,
|
|
31
|
+
operator: 'typePredicates',
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function typeNarrowed<T, P = any>(actual: T | P, expression : boolean | ((actual: T | P) => any) = true, message?: string): actual is T
|
|
37
|
+
{
|
|
38
|
+
expression = _handleExpression(actual, expression);
|
|
39
|
+
|
|
40
|
+
if (expression !== true)
|
|
41
|
+
{
|
|
42
|
+
expression = false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return expression
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default typePredicates;
|
package/src/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* use asserts for make type predicates work
|
|
3
|
-
*
|
|
4
|
-
* @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates
|
|
5
|
-
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
|
|
6
|
-
*/
|
|
7
|
-
export declare function typePredicates<T, P = any>(actual: T | P, expression?: boolean | ((actual: T | P) => any), message?: string, ignoreExpression?: boolean): asserts actual is T;
|
|
8
|
-
export declare function typeNarrowed<T, P = any>(actual: T | P, expression?: boolean | ((actual: T | P) => any), message?: string): actual is T;
|
|
9
|
-
export default typePredicates;
|
package/src/index.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.typeNarrowed = exports.typePredicates = void 0;
|
|
4
|
-
const assert_1 = require("assert");
|
|
5
|
-
/**
|
|
6
|
-
* use asserts for make type predicates work
|
|
7
|
-
*
|
|
8
|
-
* @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates
|
|
9
|
-
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
|
|
10
|
-
*/
|
|
11
|
-
function typePredicates(actual, expression = true, message, ignoreExpression) {
|
|
12
|
-
expression !== null && expression !== void 0 ? expression : (expression = true);
|
|
13
|
-
if (typeof expression === 'function') {
|
|
14
|
-
expression = !!expression(actual);
|
|
15
|
-
}
|
|
16
|
-
if (expression !== true && ignoreExpression !== true) {
|
|
17
|
-
throw new assert_1.AssertionError({
|
|
18
|
-
message: message !== null && message !== void 0 ? message : `actual ${actual} not as expected`,
|
|
19
|
-
actual,
|
|
20
|
-
expected: expression,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.typePredicates = typePredicates;
|
|
25
|
-
function typeNarrowed(actual, expression = true, message) {
|
|
26
|
-
expression !== null && expression !== void 0 ? expression : (expression = true);
|
|
27
|
-
if (typeof expression === 'function') {
|
|
28
|
-
expression = !!expression(actual);
|
|
29
|
-
}
|
|
30
|
-
if (expression !== true) {
|
|
31
|
-
expression = false;
|
|
32
|
-
}
|
|
33
|
-
return expression;
|
|
34
|
-
}
|
|
35
|
-
exports.typeNarrowed = typeNarrowed;
|
|
36
|
-
exports.default = typePredicates;
|
|
37
|
-
//# sourceMappingURL=index.js.map
|