@putout/plugin-types 5.1.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -54,6 +54,7 @@ Supported assertions:
54
54
  - `isBigInt`;
55
55
  - `isArray`;
56
56
  - `isEmptyArray`;
57
+ - `isError`;
57
58
 
58
59
  ### ❌ Example of incorrect code
59
60
 
@@ -16,6 +16,9 @@ const NAMES = {
16
16
  const EQUAL = 'typeof __a === "__b"';
17
17
  const NOT_EQUAL = 'typeof __a !== "__b"';
18
18
 
19
+ const EQUAL_INSTANCE_OF = '__a instanceof __b';
20
+ const NOT_EQUAL_INSTANCE_OF = '!(__a instanceof __b)';
21
+
19
22
  const BODIES = {
20
23
  function: `typeof __a === 'function'`,
21
24
  string: `typeof __a === 'string'`,
@@ -24,6 +27,9 @@ const BODIES = {
24
27
  undefined: `typeof __a === 'undefined'`,
25
28
  symbol: `typeof __a === 'symbol'`,
26
29
  bigint: `typeof __a === 'bigint'`,
30
+ error: `__a instanceof Error`,
31
+ array: `__a instanceof Array`,
32
+ object: `__a instanceof Object`,
27
33
  };
28
34
 
29
35
  const NOT_BODIES = {
@@ -34,12 +40,17 @@ const NOT_BODIES = {
34
40
  undefined: `typeof __a !== 'undefined'`,
35
41
  symbol: `typeof __a !== 'symbol'`,
36
42
  bigint: `typeof __a !== 'bigint'`,
43
+ error: `!(__a instanceof Error)`,
44
+ array: `!(__a instanceof Array)`,
45
+ object: `!(__a instanceof Object)`,
37
46
  };
38
47
 
39
- module.exports.report = () => `Use function to check type instead of 'typeof'`;
48
+ module.exports.report = () => `Use function to check type instead of 'typeof' or 'instanceof'`;
40
49
  module.exports.match = () => ({
41
50
  [EQUAL]: check,
42
51
  [NOT_EQUAL]: check,
52
+ [EQUAL_INSTANCE_OF]: check,
53
+ [NOT_EQUAL_INSTANCE_OF]: check,
43
54
  });
44
55
 
45
56
  module.exports.replace = () => ({
@@ -50,6 +61,9 @@ module.exports.replace = () => ({
50
61
  [BODIES.undefined]: 'isUndefined(__a)',
51
62
  [BODIES.symbol]: 'isSymbol(__a)',
52
63
  [BODIES.bigint]: 'isBigInt(__a)',
64
+ [BODIES.error]: 'isError(__a)',
65
+ [BODIES.array]: 'isArray(__a)',
66
+ [BODIES.object]: 'isObject(__a)',
53
67
  [NOT_BODIES.function]: '!isFn(__a)',
54
68
  [NOT_BODIES.string]: '!isString(__a)',
55
69
  [NOT_BODIES.number]: '!isNumber(__a)',
@@ -57,6 +71,9 @@ module.exports.replace = () => ({
57
71
  [NOT_BODIES.undefined]: '!isUndefined(__a)',
58
72
  [NOT_BODIES.symbol]: '!isSymbol(__a)',
59
73
  [NOT_BODIES.bigint]: '!isBigInt(__a)',
74
+ [NOT_BODIES.error]: '!isError(__a)',
75
+ [NOT_BODIES.array]: '!isArray(__a)',
76
+ [NOT_BODIES.object]: '!isObject(__a)',
60
77
  });
61
78
 
62
79
  function check({__a, __b}, path) {
@@ -13,4 +13,5 @@ module.exports.declare = () => ({
13
13
  isNull: `const isNull = (a) => !a && typeof a === 'object'`,
14
14
  isArray: 'const {isArray} = Array',
15
15
  isEmptyArray: 'const isEmptyArray = (a) => isArray(a) && !a.length',
16
+ isError: 'const isError = (a) => a instanceof Error',
16
17
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-types",
3
- "version": "5.1.0",
3
+ "version": "6.1.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to transform code related to types assertions",
@@ -11,7 +11,7 @@
11
11
  "changelog": false,
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "git://github.com/coderaiser/putout.git"
14
+ "url": "git+https://github.com/coderaiser/putout.git"
15
15
  },
16
16
  "scripts": {
17
17
  "test": "madrun test",
@@ -43,7 +43,7 @@
43
43
  "nodemon": "^3.0.1"
44
44
  },
45
45
  "peerDependencies": {
46
- "putout": ">=36"
46
+ "putout": ">=37"
47
47
  },
48
48
  "license": "MIT",
49
49
  "engines": {