Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 52 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 123 additions & 0 deletions recipes/util-is/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# `util.is**()`

This codemod replaces deprecated `util.is**()` methods with their modern equivalents.

See these deprecations handled by this codemod:
- [DEP0044: `util.isArray()`](https://nodejs.org/docs/latest/api/deprecations.html#DEP0044)
- [DEP0045: `util.isBoolean()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0045-utilisboolean)
- [DEP0046: `util.isBuffer()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0046-utilisbuffer)
- [DEP0047: `util.isDate()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0047-utilisdate)
- [DEP0048: `util.isError()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0048-utiliserror)
- [DEP0049: `util.isFunction()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0049-utilisfunction)
- [DEP0050: `util.isNull()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0050-utilisnull)
- [DEP0051: `util.isNullOrUndefined()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0051-utilisnullorundefined)
- [DEP0052: `util.isNumber()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0052-utilisnumber)
- [DEP0053: `util.isObject()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0053-utilisobject)
- [DEP0054: `util.isPrimitive()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0054-utilisprimitive)
- [DEP0055: `util.isRegExp()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0055-utilisregexp)
- [DEP0056: `util.isString()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0056-utilisstring)
- [DEP0057: `util.isSymbol()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0057-utilissymbol)
- [DEP0058: `util.isUndefined()`](https://nodejs.org/docs/latest/api/deprecations.html#dep0058-utilisundefined)

## Examples

**Before:**
```js
import util from 'node:util';

if (util.isArray(someValue)) {
console.log('someValue is an array');
}
if (util.isBoolean(someValue)) {
console.log('someValue is a boolean');
}
if (util.isBuffer(someValue)) {
console.log('someValue is a buffer');
}
if (util.isDate(someValue)) {
console.log('someValue is a date');
}
if (util.isError(someValue)) {
console.log('someValue is an error');
}
if (util.isFunction(someValue)) {
console.log('someValue is a function');
}
if (util.isNull(someValue)) {
console.log('someValue is null');
}
if (util.isNullOrUndefined(someValue)) {
console.log('someValue is null or undefined');
}
if (util.isNumber(someValue)) {
console.log('someValue is a number');
}
if (util.isObject(someValue)) {
console.log('someValue is an object');
}
if (util.isPrimitive(someValue)) {
console.log('someValue is a primitive');
}
if (util.isRegExp(someValue)) {
console.log('someValue is a regular expression');
}
if (util.isString(someValue)) {
console.log('someValue is a string');
}
if (util.isSymbol(someValue)) {
console.log('someValue is a symbol');
}
if (util.isUndefined(someValue)) {
console.log('someValue is undefined');
}
```

**After:**
```js

if (Array.isArray(someValue)) {
console.log('someValue is an array');
}
if (typeof someValue === 'boolean') {
console.log('someValue is a boolean');
}
if (Buffer.isBuffer(someValue)) {
console.log('someValue is a buffer');
}
if (someValue instanceof Date) {
console.log('someValue is a date');
}
if (Error.isError(someValue)) {
console.log('someValue is an error');
}
if (typeof someValue === 'function') {
console.log('someValue is a function');
}
if (someValue === null) {
console.log('someValue is null');
}
if (someValue == null) {
console.log('someValue is null or undefined');
}
if (typeof someValue === 'number') {
console.log('someValue is a number');
}
if (someValue && typeof someValue === 'object') {
console.log('someValue is an object');
}
if (Object(someValue) !== someValue) {
console.log('someValue is a primitive');
}
if (someValue instanceof RegExp) {
console.log('someValue is a regular expression');
}
if (typeof someValue === 'string') {
console.log('someValue is a string');
}
if (typeof someValue === 'symbol') {
console.log('someValue is a symbol');
}
if (typeof someValue === 'undefined') {
console.log('someValue is undefined');
}
```
21 changes: 21 additions & 0 deletions recipes/util-is/codemod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
schema_version: "1.0"
name: "@nodejs/util-is"
version: 1.0.0
description: "Replaces deprecated `util.is**()` methods with their modern equivalents."
author: Augustin Mauroy
license: MIT
workflow: workflow.yaml
category: migration

targets:
languages:
- javascript
- typescript

keywords:
- transformation
- migration

registry:
access: public
visibility: public
26 changes: 26 additions & 0 deletions recipes/util-is/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@nodejs/util-is",
"version": "1.0.0",
"description": "",
"type": "module",
"scripts": {
"test": "npx codemod@next jssg test -l typescript ./src/workflow.ts ./",
"test:update-snapshots": "npx codemod@next jssg test --update-snapshots -l typescript ./src/workflow.ts ./"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nodejs/userland-migrations.git",
"directory": "recipes/util-is",
"bugs": "https://github.com/nodejs/userland-migrations/issues"
},
"author": "Augustin Mauroy",
"license": "MIT",
"homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/util-is/README.md",
"devDependencies": {
"@types/node": "^24.0.3"
},
"dependencies": {
"@ast-grep/napi": "^0.39.1",
"@nodejs/codemod-utils": "0.0.0"
}
}
Loading
Loading