core-util-is
core-util-is is a JavaScript utility package that provides polyfills for the `util.is*` functions (e.g., `isBuffer`, `isArray`, `isNumber`, `isString`, `isRegExp`) which were originally introduced in Node.js v0.12. The package is currently at version 1.0.3 and has not been updated in approximately 4-5 years, with its last known publish around 2021. These `util.is*` functions themselves were largely deprecated in Node.js v4.0.0 (released in 2015), with Node.js core encouraging developers to use native JavaScript alternatives (like `Array.isArray()`) or more robust userland modules. The package serves primarily to maintain backward compatibility for legacy Node.js environments or applications that specifically rely on these older `util` methods. It has no direct runtime dependencies, making it a lightweight inclusion for its specific purpose.
Common errors
-
TypeError: Cannot destructure property 'isString' of require(...) as it is undefined.
cause Attempting to use ES Modules named import syntax or destructuring a non-object from a CommonJS module without a default export that provides named properties.fixEnsure you are using CommonJS `require` and correctly accessing properties from the imported object. For example, `const util = require('core-util-is'); util.isString('test');` or `const { isString } = require('core-util-is');` (if the module exports an object with these properties). -
ReferenceError: require is not defined in ES module scope
cause Attempting to use CommonJS `require()` syntax within an ES Module file (`.mjs` or `.js` when `"type": "module"` is set in `package.json`).fixIf your project is an ES Module, you will need to switch to `import util from 'core-util-is';`. Note that this will only provide a default export, and named imports will not function as expected for this CJS-only package. If possible, consider replacing the dependency with a modern alternative that supports ESM. -
Error: Cannot find module 'core-util-is'
cause This error typically indicates that the package was not correctly installed, or there's an issue with npm's cache or Node.js environment setup.fixTry deleting `node_modules` and `package-lock.json` (or `yarn.lock`), then reinstalling dependencies with `npm install` or `yarn install`. In some cases, clearing the npm cache (`npm cache clean --force`) or reinstalling Node.js may be necessary.
Warnings
- deprecated The `util.is*` functions provided by this package are deprecated in modern Node.js versions (since Node.js v4.0.0). Developers are advised to use native JavaScript methods (e.g., `Array.isArray()`, `typeof`, `instanceof`) or more robust userland libraries.
- gotcha This package is a CommonJS module and does not natively support ES Module (ESM) `import` syntax. Attempting to use named imports will lead to errors in pure ESM environments.
- breaking The package is no longer actively maintained. Its last update was around 4-5 years ago, and its GitHub repository shows minimal recent activity. This means there will be no new features, bug fixes, performance improvements, or security patches.
- gotcha Despite its inactivity, `core-util-is` has a very high number of weekly downloads (over 83 million), indicating widespread transitive dependency. This suggests that many projects might be pulling it in without direct intent, often through older dependencies that still rely on it.
Install
-
npm install core-util-is -
yarn add core-util-is -
pnpm add core-util-is
Imports
- util
import util from 'core-util-is';
const util = require('core-util-is'); - isBuffer, isArray
import { isBuffer, isArray } from 'core-util-is';const { isBuffer, isArray } = require('core-util-is'); - util.isString
import { isString } from 'core-util-is'; isString('hello');const util = require('core-util-is'); util.isString('hello');
Quickstart
const util = require('core-util-is');
console.log('Is \'hello\' a string?', util.isString('hello')); // Expected: true
console.log('Is 123 a number?', util.isNumber(123)); // Expected: true
console.log('Is [1,2,3] an array?', util.isArray([1, 2, 3])); // Expected: true
// Demonstrating a native alternative for comparison
console.log('Is [1,2,3] an array (native)?', Array.isArray([1, 2, 3])); // Expected: true