ts-type-predicates 1.0.2 → 1.0.6

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 CHANGED
@@ -3,6 +3,50 @@
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.6](https://github.com/bluelovers/ws-ts-type/compare/ts-type-predicates@1.0.5...ts-type-predicates@1.0.6) (2021-12-07)
7
+
8
+
9
+ ### 🛠 Build System
10
+
11
+ * use tsdx ([9af901a](https://github.com/bluelovers/ws-ts-type/commit/9af901a02046daf2dbb8a59086fa890757633458))
12
+
13
+
14
+
15
+
16
+
17
+ ## [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)
18
+
19
+
20
+ ### ✨ Features
21
+
22
+ * add `ignoreExpression` ([47d3b6b](https://github.com/bluelovers/ws-ts-type/commit/47d3b6bda19a27c5c23cf7ea6f7674358bb8123c))
23
+
24
+
25
+
26
+
27
+
28
+ ## [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)
29
+
30
+
31
+ ### ✨ Features
32
+
33
+ * add typeNarrowed ([e780a69](https://github.com/bluelovers/ws-ts-type/commit/e780a6924756090f8f9f13e00c91e67afa7fc6c3))
34
+
35
+
36
+
37
+
38
+
39
+ ## [1.0.3](https://github.com/bluelovers/ws-ts-type/compare/ts-type-predicates@1.0.2...ts-type-predicates@1.0.3) (2020-06-17)
40
+
41
+
42
+ ### ✨ Features
43
+
44
+ * add expression check ([40a5a44](https://github.com/bluelovers/ws-ts-type/commit/40a5a44982a8edff21d97bafbe9147bdfcc6ca60))
45
+
46
+
47
+
48
+
49
+
6
50
  ## [1.0.2](https://github.com/bluelovers/ws-ts-type/compare/ts-type-predicates@1.0.1...ts-type-predicates@1.0.2) (2020-06-17)
7
51
 
8
52
 
package/dist/index.cjs ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./index.cjs.production.min.cjs')
6
+ } else {
7
+ module.exports = require('./index.cjs.development.cjs')
8
+ }
@@ -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":[],"mappings":";;;;;;;;;;;AAAA,MAAA,OAAA,UAAA,KAAA,UAAA,EAAwC;;;;;;;;;;;;;;;;;aAoCnC,2BAAmB;;;;;;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("assert");function t(t,r=!0,o,n){var s;if(null!==(s=r)&&void 0!==s||(r=!0),"function"==typeof r&&(r=!!r(t)),!0!==r&&!0!==n)throw new e.AssertionError({message:null!=o?o:`actual ${t} not as expected`,actual:t,expected:r})}exports.default=t,exports.typeNarrowed=function(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=t;
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"],"mappings":"6JAAA,mBAAAA,0PAoCKA"}
@@ -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,37 @@
1
+ import { AssertionError } from 'assert';
2
+
3
+ function typePredicates(actual, expression = true, message, ignoreExpression) {
4
+ var _expression;
5
+
6
+ (_expression = expression) !== null && _expression !== void 0 ? _expression : expression = true;
7
+
8
+ if (typeof expression === 'function') {
9
+ expression = !!expression(actual);
10
+ }
11
+
12
+ if (expression !== true && ignoreExpression !== true) {
13
+ throw new AssertionError({
14
+ message: message !== null && message !== void 0 ? message : `actual ${actual} not as expected`,
15
+ actual,
16
+ expected: expression
17
+ });
18
+ }
19
+ }
20
+ function typeNarrowed(actual, expression = true, message) {
21
+ var _expression2;
22
+
23
+ (_expression2 = expression) !== null && _expression2 !== void 0 ? _expression2 : expression = true;
24
+
25
+ if (typeof expression === 'function') {
26
+ expression = !!expression(actual);
27
+ }
28
+
29
+ if (expression !== true) {
30
+ expression = false;
31
+ }
32
+
33
+ return expression;
34
+ }
35
+
36
+ export { typePredicates as default, typeNarrowed, typePredicates };
37
+ //# 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":[],"mappings":";;;;;;;AAAA,MAAA,OAAA,UAAA,KAAA,UAAA,EAAwC;;;;;;;;;;;;;;;;;aAoCnC,2BAAmB;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,7 +1,34 @@
1
1
  {
2
2
  "name": "ts-type-predicates",
3
- "version": "1.0.2",
3
+ "version": "1.0.6",
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
- "main": "index.js",
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}\"",
21
- "prepublishOnly": "yarn run prepublishOnly:check-bin && yarn run test",
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",
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
- "gitHead": "c68380222740dd03afdf0c62e0306924da729999"
84
+ "packageManager": "yarn@^1.22.11",
85
+ "gitHead": "9b8dbcc39d99e2c9a7bac24974950d237197c58e"
32
86
  }
@@ -4,5 +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?: any | ((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
+ export declare function typeNarrowed<T, P = any>(actual: T | P, expression?: boolean | ((actual: T | P) => any), message?: string): actual is T;
8
9
  export default typePredicates;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.typePredicates = void 0;
3
+ exports.typeNarrowed = exports.typePredicates = void 0;
4
4
  const assert_1 = require("assert");
5
5
  /**
6
6
  * use asserts for make type predicates work
@@ -8,19 +8,30 @@ 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
+ expression !== null && expression !== void 0 ? expression : (expression = true);
12
13
  if (typeof expression === 'function') {
13
- expression = expression(actual);
14
+ expression = !!expression(actual);
14
15
  }
15
- if (!expression) {
16
+ if (expression !== true && ignoreExpression !== true) {
16
17
  throw new assert_1.AssertionError({
17
18
  message: message !== null && message !== void 0 ? message : `actual ${actual} not as expected`,
18
19
  actual,
19
20
  expected: expression,
20
21
  });
21
22
  }
22
- return expression;
23
23
  }
24
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;
25
36
  exports.default = typePredicates;
26
37
  //# sourceMappingURL=index.js.map
@@ -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,aAA8C,IAAI,EAAE,OAAgB;IAE7H,IAAI,OAAO,UAAU,KAAK,UAAU,EACpC;QACC,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;KAChC;IAED,IAAI,CAAC,UAAU,EACf;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;IAED,OAAO,UAAU,CAAA;AAClB,CAAC;AAjBD,wCAiBC;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 : any | ((actual: T | P) => any) = true, message?: string): asserts actual is T\n{\n\tif (typeof expression === 'function')\n\t{\n\t\texpression = expression(actual);\n\t}\n\n\tif (!expression)\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\treturn expression\n}\n\nexport default typePredicates;\n"]}