@putout/plugin-types 6.1.0 → 7.0.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 +6 -0
- package/lib/convert-typeof-to-is-type/index.js +10 -1
- package/lib/declare/index.js +2 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -45,6 +45,7 @@ Supported assertions:
|
|
|
45
45
|
- `isString`;
|
|
46
46
|
- `isEmptyString`;
|
|
47
47
|
- `isNumber`;
|
|
48
|
+
- `isNumberLike` - checks if `a` can be convert to `Number` from `String`;
|
|
48
49
|
- `isFn`;
|
|
49
50
|
- `isBool`;
|
|
50
51
|
- `isObject`;
|
|
@@ -60,13 +61,18 @@ Supported assertions:
|
|
|
60
61
|
|
|
61
62
|
```js
|
|
62
63
|
isString('hello');
|
|
64
|
+
isNumber('a' - 5);
|
|
63
65
|
```
|
|
64
66
|
|
|
65
67
|
### ✅ Example of correct code
|
|
66
68
|
|
|
67
69
|
```js
|
|
68
70
|
const isString = (a) => typeof a === 'string';
|
|
71
|
+
const isNumber = (a) => !Number.isNaN(a) && typeof a === 'number';
|
|
72
|
+
|
|
69
73
|
isString('hello');
|
|
74
|
+
|
|
75
|
+
isNumber('a' - 5);
|
|
70
76
|
```
|
|
71
77
|
|
|
72
78
|
When you want to skip some declaration use `dismiss`:
|
|
@@ -19,6 +19,9 @@ const NOT_EQUAL = 'typeof __a !== "__b"';
|
|
|
19
19
|
const EQUAL_INSTANCE_OF = '__a instanceof __b';
|
|
20
20
|
const NOT_EQUAL_INSTANCE_OF = '!(__a instanceof __b)';
|
|
21
21
|
|
|
22
|
+
const EQUAL_UNDEFINED = '__a === undefined';
|
|
23
|
+
const NOT_EQUAL_UNDEFINED = '__a !== undefined';
|
|
24
|
+
|
|
22
25
|
const BODIES = {
|
|
23
26
|
function: `typeof __a === 'function'`,
|
|
24
27
|
string: `typeof __a === 'string'`,
|
|
@@ -30,6 +33,7 @@ const BODIES = {
|
|
|
30
33
|
error: `__a instanceof Error`,
|
|
31
34
|
array: `__a instanceof Array`,
|
|
32
35
|
object: `__a instanceof Object`,
|
|
36
|
+
equalUndefined: '__a === undefined',
|
|
33
37
|
};
|
|
34
38
|
|
|
35
39
|
const NOT_BODIES = {
|
|
@@ -43,6 +47,7 @@ const NOT_BODIES = {
|
|
|
43
47
|
error: `!(__a instanceof Error)`,
|
|
44
48
|
array: `!(__a instanceof Array)`,
|
|
45
49
|
object: `!(__a instanceof Object)`,
|
|
50
|
+
equalUndefined: '__a !== undefined',
|
|
46
51
|
};
|
|
47
52
|
|
|
48
53
|
module.exports.report = () => `Use function to check type instead of 'typeof' or 'instanceof'`;
|
|
@@ -51,6 +56,8 @@ module.exports.match = () => ({
|
|
|
51
56
|
[NOT_EQUAL]: check,
|
|
52
57
|
[EQUAL_INSTANCE_OF]: check,
|
|
53
58
|
[NOT_EQUAL_INSTANCE_OF]: check,
|
|
59
|
+
[EQUAL_UNDEFINED]: check,
|
|
60
|
+
[NOT_EQUAL_UNDEFINED]: check,
|
|
54
61
|
});
|
|
55
62
|
|
|
56
63
|
module.exports.replace = () => ({
|
|
@@ -64,6 +71,7 @@ module.exports.replace = () => ({
|
|
|
64
71
|
[BODIES.error]: 'isError(__a)',
|
|
65
72
|
[BODIES.array]: 'isArray(__a)',
|
|
66
73
|
[BODIES.object]: 'isObject(__a)',
|
|
74
|
+
[BODIES.equalUndefined]: 'isUndefined(__a)',
|
|
67
75
|
[NOT_BODIES.function]: '!isFn(__a)',
|
|
68
76
|
[NOT_BODIES.string]: '!isString(__a)',
|
|
69
77
|
[NOT_BODIES.number]: '!isNumber(__a)',
|
|
@@ -74,13 +82,14 @@ module.exports.replace = () => ({
|
|
|
74
82
|
[NOT_BODIES.error]: '!isError(__a)',
|
|
75
83
|
[NOT_BODIES.array]: '!isArray(__a)',
|
|
76
84
|
[NOT_BODIES.object]: '!isObject(__a)',
|
|
85
|
+
[NOT_BODIES.equalUndefined]: '!isUndefined(__a)',
|
|
77
86
|
});
|
|
78
87
|
|
|
79
88
|
function check({__a, __b}, path) {
|
|
80
89
|
if (path.parentPath.isFunction())
|
|
81
90
|
return false;
|
|
82
91
|
|
|
83
|
-
if (isBind(path, __b.value))
|
|
92
|
+
if (__b && isBind(path, __b.value))
|
|
84
93
|
return false;
|
|
85
94
|
|
|
86
95
|
return getBindingPath(path, __a);
|
package/lib/declare/index.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
module.exports.declare = () => ({
|
|
4
4
|
isString: `const isString = (a) => typeof a === 'string'`,
|
|
5
5
|
isEmptyString: `const isEmptyString = (a) => !a && isString(a)`,
|
|
6
|
-
isNumber: `const isNumber = (a) => typeof a === 'number'`,
|
|
6
|
+
isNumber: `const isNumber = (a) => !Number.isNaN(a) && typeof a === 'number'`,
|
|
7
|
+
isNumberLike: `const isNumberLike = (a, b = Number(a)) => isNumber(b)`,
|
|
7
8
|
isFn: `const isFn = (a) => typeof a === 'function'`,
|
|
8
9
|
isBool: `const isBool = (a) => typeof a === 'boolean'`,
|
|
9
10
|
isObject: `const isObject = (a) => a && typeof a === 'object'`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-types",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.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",
|
|
@@ -31,19 +31,20 @@
|
|
|
31
31
|
"types"
|
|
32
32
|
],
|
|
33
33
|
"devDependencies": {
|
|
34
|
+
"@putout/eslint-flat": "^2.0.0",
|
|
34
35
|
"@putout/plugin-putout": "*",
|
|
35
36
|
"@putout/test": "^11.0.0",
|
|
36
37
|
"c8": "^10.0.0",
|
|
37
38
|
"eslint": "^9.0.0",
|
|
38
39
|
"eslint-plugin-n": "^17.0.0",
|
|
39
|
-
"eslint-plugin-putout": "^
|
|
40
|
+
"eslint-plugin-putout": "^24.0.0",
|
|
40
41
|
"lerna": "^6.0.1",
|
|
41
42
|
"madrun": "^10.0.0",
|
|
42
43
|
"montag": "^1.2.1",
|
|
43
44
|
"nodemon": "^3.0.1"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
|
-
"putout": ">=
|
|
47
|
+
"putout": ">=38"
|
|
47
48
|
},
|
|
48
49
|
"license": "MIT",
|
|
49
50
|
"engines": {
|