ts-type-predicates 1.0.4 → 1.0.7
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 +33 -0
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.development.cjs +43 -0
- package/dist/index.cjs.development.cjs.map +1 -0
- package/dist/index.cjs.production.min.cjs +2 -0
- package/dist/index.cjs.production.min.cjs.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.esm.mjs +20 -0
- package/dist/index.esm.mjs.map +1 -0
- package/dist/index.umd.development.cjs +47 -0
- package/dist/index.umd.development.cjs.map +1 -0
- package/dist/index.umd.production.min.cjs +2 -0
- package/dist/index.umd.production.min.cjs.map +1 -0
- package/package.json +58 -4
- package/{index.d.ts → src/index.d.ts} +1 -1
- package/{index.js → src/index.js} +2 -2
- package/src/index.js.map +1 -0
- package/index.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,39 @@
|
|
|
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.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
|
+
|
|
8
|
+
|
|
9
|
+
### 🔖 Miscellaneous
|
|
10
|
+
|
|
11
|
+
* . ([e660f8e](https://github.com/bluelovers/ws-ts-type/commit/e660f8e0b4e0afda0bfabfbcbe8e2c10b3e69a80))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [1.0.6](https://github.com/bluelovers/ws-ts-type/compare/ts-type-predicates@1.0.5...ts-type-predicates@1.0.6) (2021-12-07)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### 🛠 Build System
|
|
21
|
+
|
|
22
|
+
* use tsdx ([9af901a](https://github.com/bluelovers/ws-ts-type/commit/9af901a02046daf2dbb8a59086fa890757633458))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## [1.0.5](https://github.com/bluelovers/ws-ts-type/compare/ts-type-predicates@1.0.4...ts-type-predicates@1.0.5) (2021-07-27)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### ✨ Features
|
|
32
|
+
|
|
33
|
+
* add `ignoreExpression` ([47d3b6b](https://github.com/bluelovers/ws-ts-type/commit/47d3b6bda19a27c5c23cf7ea6f7674358bb8123c))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
6
39
|
## [1.0.4](https://github.com/bluelovers/ws-ts-type/compare/ts-type-predicates@1.0.3...ts-type-predicates@1.0.4) (2021-07-22)
|
|
7
40
|
|
|
8
41
|
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var assert = require('assert');
|
|
6
|
+
|
|
7
|
+
function typePredicates(actual, expression = true, message, ignoreExpression) {
|
|
8
|
+
var _expression;
|
|
9
|
+
|
|
10
|
+
(_expression = expression) !== null && _expression !== void 0 ? _expression : expression = true;
|
|
11
|
+
|
|
12
|
+
if (typeof expression === 'function') {
|
|
13
|
+
expression = !!expression(actual);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (expression !== true && ignoreExpression !== true) {
|
|
17
|
+
throw new assert.AssertionError({
|
|
18
|
+
message: message !== null && message !== void 0 ? message : `actual ${actual} not as expected`,
|
|
19
|
+
actual,
|
|
20
|
+
expected: expression
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function typeNarrowed(actual, expression = true, message) {
|
|
25
|
+
var _expression2;
|
|
26
|
+
|
|
27
|
+
(_expression2 = expression) !== null && _expression2 !== void 0 ? _expression2 : expression = true;
|
|
28
|
+
|
|
29
|
+
if (typeof expression === 'function') {
|
|
30
|
+
expression = !!expression(actual);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (expression !== true) {
|
|
34
|
+
expression = false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return expression;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports["default"] = typePredicates;
|
|
41
|
+
exports.typeNarrowed = typeNarrowed;
|
|
42
|
+
exports.typePredicates = typePredicates;
|
|
43
|
+
//# sourceMappingURL=index.cjs.development.cjs.map
|
|
@@ -0,0 +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 ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\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})\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 ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\n\n\tif (expression !== true)\n\t{\n\t\texpression = false;\n\t}\n\n\treturn expression\n}\n\nexport default typePredicates;\n"],"names":["expected","expression"],"mappings":";;;;;;;;;;;EAAA,IAAwC,OAAA,UAAA,KAAA,UAAA,EAAA;;;;;;;;AAoBrCA,MAAAA,QAAAA,EAAAA,UAAAA;;AAID,GAAA;;;;;EASA,CAAA,YAAA,GAAA,UAAA,MAAA,IAAA,IAAA,YAAA,KAAA,KAAA,CAAA,GAAA,YAAA,GAAA,UAAA,GAAA,IAAA,CAAA;;aAGGC,eAAA,UAAmB,EAAA;iBAEZ,CAAA,CAAA,UAAA,CAAA,MAAA,CAAA,CAAA;;;gBAGX;AACA,IAAA,UAAA,GAAA,KAAA,CAAA;AAED,GAAA;;;AAxBG;;;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("assert");function typePredicates(t,r=!0,o,a){var s;if(null!==(s=r)&&void 0!==s||(r=!0),"function"==typeof r&&(r=!!r(t)),!0!==r&&!0!==a)throw new e.AssertionError({message:null!=o?o:`actual ${t} not as expected`,actual:t,expected:r})}exports.default=typePredicates,exports.typeNarrowed=function typeNarrowed(e,t=!0,r){var o;return null!==(o=t)&&void 0!==o||(t=!0),"function"==typeof t&&(t=!!t(e)),!0!==t&&(t=!1),t},exports.typePredicates=typePredicates;
|
|
2
|
+
//# sourceMappingURL=index.cjs.production.min.cjs.map
|
|
@@ -0,0 +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 ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\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})\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 ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\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","expected","_expression2","actual"],"mappings":"0KAAwC,mBAAAA,kHAoBrCC,SAAAA,qGAaD,QAAAC,EAAAF,SAAA,IAAAE,IAAAF,GAAA,GAGG,mBAAAA,QAEOA,EAAAG,aAIXH,GAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
10
|
+
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AssertionError as e } from "assert";
|
|
2
|
+
|
|
3
|
+
function typePredicates(t, a = !0, r, o) {
|
|
4
|
+
var n;
|
|
5
|
+
if (null !== (n = a) && void 0 !== n || (a = !0), "function" == typeof a && (a = !!a(t)),
|
|
6
|
+
!0 !== a && !0 !== o) throw new e({
|
|
7
|
+
message: null != r ? r : `actual ${t} not as expected`,
|
|
8
|
+
actual: t,
|
|
9
|
+
expected: a
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function typeNarrowed(e, t = !0, a) {
|
|
14
|
+
var r;
|
|
15
|
+
return null !== (r = t) && void 0 !== r || (t = !0), "function" == typeof t && (t = !!t(e)),
|
|
16
|
+
!0 !== t && (t = !1), t;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { typePredicates as default, typeNarrowed, typePredicates };
|
|
20
|
+
//# sourceMappingURL=index.esm.mjs.map
|
|
@@ -0,0 +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 ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\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})\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 ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\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","expected","_expression2","actual"],"mappings":";;;;oDAAwC,qBAAAA;;;;IAoBrCC,UAAAA;;;;;;SAaD,UAAAC,IAAAF,WAAA,MAAAE,MAAAF,KAAA,IAGG,qBAAAA,YAEOA,EAAAG;eAIXH,KAAA;;;"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('assert')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'assert'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TsTypePredicates = {}, global.assert));
|
|
5
|
+
})(this, (function (exports, assert) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function typePredicates(actual, expression = true, message, ignoreExpression) {
|
|
8
|
+
var _expression;
|
|
9
|
+
|
|
10
|
+
(_expression = expression) !== null && _expression !== void 0 ? _expression : expression = true;
|
|
11
|
+
|
|
12
|
+
if (typeof expression === 'function') {
|
|
13
|
+
expression = !!expression(actual);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (expression !== true && ignoreExpression !== true) {
|
|
17
|
+
throw new assert.AssertionError({
|
|
18
|
+
message: message !== null && message !== void 0 ? message : `actual ${actual} not as expected`,
|
|
19
|
+
actual,
|
|
20
|
+
expected: expression
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function typeNarrowed(actual, expression = true, message) {
|
|
25
|
+
var _expression2;
|
|
26
|
+
|
|
27
|
+
(_expression2 = expression) !== null && _expression2 !== void 0 ? _expression2 : expression = true;
|
|
28
|
+
|
|
29
|
+
if (typeof expression === 'function') {
|
|
30
|
+
expression = !!expression(actual);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (expression !== true) {
|
|
34
|
+
expression = false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return expression;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports["default"] = typePredicates;
|
|
41
|
+
exports.typeNarrowed = typeNarrowed;
|
|
42
|
+
exports.typePredicates = typePredicates;
|
|
43
|
+
|
|
44
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
45
|
+
|
|
46
|
+
}));
|
|
47
|
+
//# sourceMappingURL=index.umd.development.cjs.map
|
|
@@ -0,0 +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 ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\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})\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 ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\n\n\tif (expression !== true)\n\t{\n\t\texpression = false;\n\t}\n\n\treturn expression\n}\n\nexport default typePredicates;\n"],"names":["expected","expression"],"mappings":";;;;;;;;;;;GAAA,IAAwC,OAAA,UAAA,KAAA,UAAA,EAAA;;;;;;;;CAoBrCA,MAAAA,QAAAA,EAAAA,UAAAA;;CAID,GAAA;;;;;GASA,CAAA,YAAA,GAAA,UAAA,MAAA,IAAA,IAAA,YAAA,KAAA,KAAA,CAAA,GAAA,YAAA,GAAA,UAAA,GAAA,IAAA,CAAA;;cAGGC,eAAA,UAAmB,EAAA;kBAEZ,CAAA,CAAA,UAAA,CAAA,MAAA,CAAA,CAAA;;;iBAGX;CACA,IAAA,UAAA,GAAA,KAAA,CAAA;CAED,GAAA;;;CAxBG;;;;;;;;;;;;"}
|
|
@@ -0,0 +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 typePredicates(e,o=!0,n,r){var i;if(null!==(i=o)&&void 0!==i||(o=!0),"function"==typeof o&&(o=!!o(e)),!0!==o&&!0!==r)throw new t.AssertionError({message:null!=n?n:`actual ${e} not as expected`,actual:e,expected:o})}e.default=typePredicates,e.typeNarrowed=function typeNarrowed(e,t=!0,o){var n;return null!==(n=t)&&void 0!==n||(t=!0),"function"==typeof t&&(t=!!t(e)),!0!==t&&(t=!1),t},e.typePredicates=typePredicates,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
|
+
//# sourceMappingURL=index.umd.production.min.cjs.map
|
|
@@ -0,0 +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 ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\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})\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 ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\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","expected","_expression2","actual"],"mappings":"4WAAwC,mBAAAA,kHAoBrCC,SAAAA,yFAaD,QAAAC,EAAAF,SAAA,IAAAE,IAAAF,GAAA,GAGG,mBAAAA,QAEOA,EAAAG,aAIXH,GAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-type-predicates",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "use asserts for make type predicates work",
|
|
5
|
+
"keywords": [
|
|
6
|
+
".d.ts",
|
|
7
|
+
"@types",
|
|
8
|
+
"declaration",
|
|
9
|
+
"dev",
|
|
10
|
+
"develop",
|
|
11
|
+
"development",
|
|
12
|
+
"environment",
|
|
13
|
+
"ide",
|
|
14
|
+
"interface",
|
|
15
|
+
"node",
|
|
16
|
+
"playground",
|
|
17
|
+
"runtime",
|
|
18
|
+
"ts",
|
|
19
|
+
"type",
|
|
20
|
+
"type-level",
|
|
21
|
+
"typelevel",
|
|
22
|
+
"types",
|
|
23
|
+
"typescript",
|
|
24
|
+
"typing",
|
|
25
|
+
"typings",
|
|
26
|
+
"type-helprt",
|
|
27
|
+
"toolbox",
|
|
28
|
+
"toolbelt",
|
|
29
|
+
"create-by-yarn-tool",
|
|
30
|
+
"create-by-tsdx"
|
|
31
|
+
],
|
|
5
32
|
"homepage": "https://github.com/bluelovers/ws-ts-type/tree/master/packages/ts-type-predicates#readme",
|
|
6
33
|
"bugs": {
|
|
7
34
|
"url": "https://github.com/bluelovers/ws-ts-type/issues"
|
|
@@ -12,21 +39,48 @@
|
|
|
12
39
|
},
|
|
13
40
|
"license": "ISC",
|
|
14
41
|
"author": "bluelovers",
|
|
15
|
-
"
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"import": "./dist/index.esm.mjs",
|
|
46
|
+
"require": "./dist/index.cjs"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"main": "dist/index.cjs",
|
|
50
|
+
"module": "dist/index.esm.mjs",
|
|
51
|
+
"types": "dist/index.d.ts",
|
|
52
|
+
"typings": "dist/index.d.ts",
|
|
53
|
+
"directories": {
|
|
54
|
+
"test": "test"
|
|
55
|
+
},
|
|
16
56
|
"scripts": {
|
|
17
57
|
"lint": "ynpx --quiet eslint -- **/*.ts",
|
|
18
58
|
"test": "echo \"Error: no test specified\"",
|
|
19
59
|
"test:jest": "ynpx --quiet jest -- --coverage",
|
|
20
60
|
"test:mocha": "ynpx --quiet -p ts-node -p mocha mocha -- --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"",
|
|
61
|
+
"posttest": "yarn run build",
|
|
62
|
+
"build": "yarn run build:tsdx && yarn run build:dts",
|
|
63
|
+
"build:dts": "ynpx dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts --no-banner & echo build:dts",
|
|
64
|
+
"build:tsdx": "ynpx @bluelovers/tsdx build --target node --name index",
|
|
65
|
+
"preversion": "echo preversion && yarn run test",
|
|
66
|
+
"version": "echo version",
|
|
67
|
+
"postversion": "echo postversion",
|
|
68
|
+
"prepublish": "echo prepublish",
|
|
69
|
+
"prepublishOnly": "echo prepublishOnly",
|
|
21
70
|
"prepublishOnly_": "yarn run prepublishOnly:check-bin && yarn run test",
|
|
22
71
|
"prepublishOnly:check-bin": "ynpx --quiet @yarn-tool/check-pkg-bin",
|
|
23
72
|
"prepublishOnly:update": "yarn run ncu && yarn run sort-package-json",
|
|
73
|
+
"publish": "echo publish",
|
|
74
|
+
"postpublish": "echo postpublish",
|
|
75
|
+
"postpublishOnly": "echo postpublishOnly",
|
|
24
76
|
"ncu": "ynpx --quiet yarn-tool -- ncu -u",
|
|
25
|
-
"sort-package-json": "ynpx --quiet yarn-tool -- sort"
|
|
77
|
+
"sort-package-json": "ynpx --quiet yarn-tool -- sort",
|
|
78
|
+
"tsc:showConfig": "ynpx get-current-tsconfig -p"
|
|
26
79
|
},
|
|
27
80
|
"devDependencies": {
|
|
28
81
|
"@bluelovers/tsconfig": "*",
|
|
29
82
|
"@types/node": "*"
|
|
30
83
|
},
|
|
31
|
-
"
|
|
84
|
+
"packageManager": "yarn@^1.22.11",
|
|
85
|
+
"gitHead": "a194b9c8616dc5f83df145ed071dc67ce65c27a0"
|
|
32
86
|
}
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates
|
|
5
5
|
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
|
|
6
6
|
*/
|
|
7
|
-
export declare function typePredicates<T, P = any>(actual: T | P, expression?: boolean | ((actual: T | P) => any), message?: string): asserts actual is T;
|
|
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
8
|
export declare function typeNarrowed<T, P = any>(actual: T | P, expression?: boolean | ((actual: T | P) => any), message?: string): actual is T;
|
|
9
9
|
export default typePredicates;
|
|
@@ -8,12 +8,12 @@ const assert_1 = require("assert");
|
|
|
8
8
|
* @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates
|
|
9
9
|
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
|
|
10
10
|
*/
|
|
11
|
-
function typePredicates(actual, expression = true, message) {
|
|
11
|
+
function typePredicates(actual, expression = true, message, ignoreExpression) {
|
|
12
12
|
expression !== null && expression !== void 0 ? expression : (expression = true);
|
|
13
13
|
if (typeof expression === 'function') {
|
|
14
14
|
expression = !!expression(actual);
|
|
15
15
|
}
|
|
16
|
-
if (expression !== true) {
|
|
16
|
+
if (expression !== true && ignoreExpression !== true) {
|
|
17
17
|
throw new assert_1.AssertionError({
|
|
18
18
|
message: message !== null && message !== void 0 ? message : `actual ${actual} not as expected`,
|
|
19
19
|
actual,
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,mCAAwC;AAExC;;;;;GAKG;AACH,SAAgB,cAAc,CAAa,MAAa,EAAE,aAAkD,IAAI,EAAE,OAAgB,EAAE,gBAA0B;IAE7J,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,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;SACpB,CAAC,CAAA;KACF;AACF,CAAC;AAjBD,wCAiBC;AAED,SAAgB,YAAY,CAAa,MAAa,EAAE,aAAkD,IAAI,EAAE,OAAgB;IAE/H,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,IAAI,UAAU,KAAK,IAAI,EACvB;QACC,UAAU,GAAG,KAAK,CAAC;KACnB;IAED,OAAO,UAAU,CAAA;AAClB,CAAC;AAfD,oCAeC;AAED,kBAAe,cAAc,CAAC","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 ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\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})\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 ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\n\n\tif (expression !== true)\n\t{\n\t\texpression = false;\n\t}\n\n\treturn expression\n}\n\nexport default typePredicates;\n"]}
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,mCAAwC;AAExC;;;;;GAKG;AACH,SAAgB,cAAc,CAAa,MAAa,EAAE,aAAkD,IAAI,EAAE,OAAgB;IAEjI,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,IAAI,UAAU,KAAK,IAAI,EACvB;QACC,MAAM,IAAI,uBAAc,CAAC;YACxB,OAAO,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,UAAU,MAAM,kBAAkB;YACtD,MAAM;YACN,QAAQ,EAAE,UAAU;SACpB,CAAC,CAAA;KACF;AACF,CAAC;AAjBD,wCAiBC;AAED,SAAgB,YAAY,CAAa,MAAa,EAAE,aAAkD,IAAI,EAAE,OAAgB;IAE/H,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,IAAI,UAAU,KAAK,IAAI,EACvB;QACC,UAAU,GAAG,KAAK,CAAC;KACnB;IAED,OAAO,UAAU,CAAA;AAClB,CAAC;AAfD,oCAeC;AAED,kBAAe,cAAc,CAAC","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): asserts actual is T\n{\n\texpression ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\n\n\tif (expression !== 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})\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 ??= true;\n\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = !!expression(actual);\n\t}\n\n\tif (expression !== true)\n\t{\n\t\texpression = false;\n\t}\n\n\treturn expression\n}\n\nexport default typePredicates;\n"]}
|