This codemod replaces the following deprecated util.is*() methods with their modern equivalents.
What It Does
This codemod handles 15 deprecated type-checking methods:
util.isArray() → Array.isArray()
util.isBoolean() → typeof value === 'boolean'
util.isBuffer() → Buffer.isBuffer()
util.isDate() → value instanceof Date
util.isError() → Error.isError()
util.isFunction() → typeof value === 'function'
util.isNull() → value === null
util.isNullOrUndefined() → value === null || value === undefined
util.isNumber() → typeof value === 'number'
util.isObject() → value && typeof value === 'object'
util.isPrimitive() → Object(value) !== value
util.isRegExp() → value instanceof RegExp
util.isString() → typeof value === 'string'
util.isSymbol() → typeof value === 'symbol'
util.isUndefined() → typeof value === 'undefined'
Before/After Examples
Type Checks
Before:
const util = require('node:util');
if (util.isArray(value)) { }
if (util.isString(value)) { }
if (util.isNumber(value)) { }
After:
if (Array.isArray(value)) { }
if (typeof value === 'string') { }
if (typeof value === 'number') { }
Object Type Checks
Before:
const util = require('node:util');
if (util.isDate(value)) { }
if (util.isRegExp(value)) { }
if (util.isBuffer(value)) { }
After:
if (value instanceof Date) { }
if (value instanceof RegExp) { }
if (Buffer.isBuffer(value)) { }
Null/Undefined Checks
Before:
const util = require('node:util');
if (util.isNull(value)) { }
if (util.isUndefined(value)) { }
if (util.isNullOrUndefined(value)) { }
After:
if (value === null) { }
if (typeof value === 'undefined') { }
if (value === null || value === undefined) { }
Usage
Run this codemod on your project:
npx codemod node/userland/util-is
Modern JavaScript provides native type-checking mechanisms that are more performant and widely understood. These standard approaches are preferred over Node.js-specific utilities.