1
1
# ` util.is**() `
2
2
3
- This codemod replaces deprecated ` util.is**() ` methods with their modern equivalents.
4
-
5
- See these deprecations handled by this codemod:
3
+ This codemod replaces the following deprecated ` util.is**() ` methods with their modern equivalents:
6
4
- [ DEP0044: ` util.isArray() ` ] ( https://nodejs.org/docs/latest/api/deprecations.html#DEP0044 )
7
5
- [ DEP0045: ` util.isBoolean() ` ] ( https://nodejs.org/docs/latest/api/deprecations.html#dep0045-utilisboolean )
8
6
- [ DEP0046: ` util.isBuffer() ` ] ( https://nodejs.org/docs/latest/api/deprecations.html#dep0046-utilisbuffer )
@@ -21,103 +19,20 @@ See these deprecations handled by this codemod:
21
19
22
20
## Examples
23
21
24
- ** Before:**
25
- ``` js
26
- import util from ' node:util' ;
27
-
28
- if (util .isArray (someValue)) {
29
- console .log (' someValue is an array' );
30
- }
31
- if (util .isBoolean (someValue)) {
32
- console .log (' someValue is a boolean' );
33
- }
34
- if (util .isBuffer (someValue)) {
35
- console .log (' someValue is a buffer' );
36
- }
37
- if (util .isDate (someValue)) {
38
- console .log (' someValue is a date' );
39
- }
40
- if (util .isError (someValue)) {
41
- console .log (' someValue is an error' );
42
- }
43
- if (util .isFunction (someValue)) {
44
- console .log (' someValue is a function' );
45
- }
46
- if (util .isNull (someValue)) {
47
- console .log (' someValue is null' );
48
- }
49
- if (util .isNullOrUndefined (someValue)) {
50
- console .log (' someValue is null or undefined' );
51
- }
52
- if (util .isNumber (someValue)) {
53
- console .log (' someValue is a number' );
54
- }
55
- if (util .isObject (someValue)) {
56
- console .log (' someValue is an object' );
57
- }
58
- if (util .isPrimitive (someValue)) {
59
- console .log (' someValue is a primitive' );
60
- }
61
- if (util .isRegExp (someValue)) {
62
- console .log (' someValue is a regular expression' );
63
- }
64
- if (util .isString (someValue)) {
65
- console .log (' someValue is a string' );
66
- }
67
- if (util .isSymbol (someValue)) {
68
- console .log (' someValue is a symbol' );
69
- }
70
- if (util .isUndefined (someValue)) {
71
- console .log (' someValue is undefined' );
72
- }
73
- ```
74
-
75
- ** After:**
76
- ``` js
77
-
78
- if (Array .isArray (someValue)) {
79
- console .log (' someValue is an array' );
80
- }
81
- if (typeof someValue === ' boolean' ) {
82
- console .log (' someValue is a boolean' );
83
- }
84
- if (Buffer .isBuffer (someValue)) {
85
- console .log (' someValue is a buffer' );
86
- }
87
- if (someValue instanceof Date ) {
88
- console .log (' someValue is a date' );
89
- }
90
- if (Error .isError (someValue)) {
91
- console .log (' someValue is an error' );
92
- }
93
- if (typeof someValue === ' function' ) {
94
- console .log (' someValue is a function' );
95
- }
96
- if (someValue === null ) {
97
- console .log (' someValue is null' );
98
- }
99
- if (someValue == null ) {
100
- console .log (' someValue is null or undefined' );
101
- }
102
- if (typeof someValue === ' number' ) {
103
- console .log (' someValue is a number' );
104
- }
105
- if (someValue && typeof someValue === ' object' ) {
106
- console .log (' someValue is an object' );
107
- }
108
- if (Object (someValue) !== someValue) {
109
- console .log (' someValue is a primitive' );
110
- }
111
- if (someValue instanceof RegExp ) {
112
- console .log (' someValue is a regular expression' );
113
- }
114
- if (typeof someValue === ' string' ) {
115
- console .log (' someValue is a string' );
116
- }
117
- if (typeof someValue === ' symbol' ) {
118
- console .log (' someValue is a symbol' );
119
- }
120
- if (typeof someValue === ' undefined' ) {
121
- console .log (' someValue is undefined' );
122
- }
123
- ```
22
+ | ** Before** | ** After** |
23
+ | --------------------------------| ---------------------------------|
24
+ | ` util.isArray(someValue ` | ` Array.isArray(someValue ` |
25
+ | ` util.isBoolean(someValue ` | ` typeof someValue === 'boolean' ` |
26
+ | ` util.isBuffer(someValue ` | ` Buffer.isBuffer(someValue ` |
27
+ | ` util.isDate(someValue ` | ` someValue instanceof Date ` |
28
+ | ` util.isError(someValue ` | ` Error.isError(someValue ` |
29
+ | ` util.isFunction(someValue ` | ` typeof someValue === 'function' ` |
30
+ | ` util.isNull(someValue ` | ` someValue === null ` |
31
+ | ` util.isNullOrUndefined(someValue ` | ` someValue == null ` |
32
+ | ` util.isNumber(someValue ` | ` typeof someValue === 'number' ` |
33
+ | ` util.isObject(someValue ` | ` someValue && typeof someValue === 'object' ` |
34
+ | ` util.isPrimitive(someValue ` | ` Object(someValue) !== someValue ` |
35
+ | ` util.isRegExp(someValue ` | ` someValue instanceof RegExp ` |
36
+ | ` util.isString(someValue ` | ` typeof someValue === 'string' ` |
37
+ | ` util.isSymbol(someValue ` | ` typeof someValue === 'symbol' ` |
38
+ | ` util.isUndefined(someValue ` | ` typeof someValue === 'undefined' ` |
0 commit comments