Skip to content

Commit f679a55

Browse files
update from feedback
Co-Authored-By: Jacob Smith <[email protected]>
1 parent e9df057 commit f679a55

File tree

6 files changed

+102
-154
lines changed

6 files changed

+102
-154
lines changed

package-lock.json

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

recipes/util-is/README.md

Lines changed: 18 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# `util.is**()`
22

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:
64
- [DEP0044: `util.isArray()`](https://nodejs.org/docs/latest/api/deprecations.html#DEP0044)
75
- [DEP0045: `util.isBoolean()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0045-utilisboolean)
86
- [DEP0046: `util.isBuffer()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0046-utilisbuffer)
@@ -21,103 +19,20 @@ See these deprecations handled by this codemod:
2119

2220
## Examples
2321

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'` |

recipes/util-is/codemod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
schema_version: "1.0"
22
name: "@nodejs/util-is"
33
version: 1.0.0
4-
description: "Replaces deprecated `util.is**()` methods with their modern equivalents."
4+
description: "Replaces deprecated `util.is*()` methods with their modern equivalents."
55
author: Augustin Mauroy
66
license: MIT
77
workflow: workflow.yaml

recipes/util-is/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"name": "@nodejs/util-is",
33
"version": "1.0.0",
4-
"description": "",
4+
"description": "Replaces deprecated `util.is*()` methods with their modern equivalents.",
55
"type": "module",
66
"scripts": {
7-
"test": "npx codemod@next jssg test -l typescript ./src/workflow.ts ./",
8-
"test:update-snapshots": "npx codemod@next jssg test --update-snapshots -l typescript ./src/workflow.ts ./"
7+
"test": "npx codemod@next jssg test -l typescript ./src/workflow.ts ./"
98
},
109
"repository": {
1110
"type": "git",
@@ -17,10 +16,9 @@
1716
"license": "MIT",
1817
"homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/util-is/README.md",
1918
"devDependencies": {
20-
"@types/node": "^24.0.3"
19+
"@codemod.com/jssg-types": "^1.0.3"
2120
},
2221
"dependencies": {
23-
"@ast-grep/napi": "^0.39.1",
2422
"@nodejs/codemod-utils": "0.0.0"
2523
}
2624
}

0 commit comments

Comments
 (0)