Registry / devops / class-utils

class-utils

JSON →
library0.0.5jsnpmunverified

class-utils is a JavaScript utility library designed to assist developers in working with and manipulating JavaScript classes and their prototype methods. As of its current stable version, 0.3.6, it provides functions for tasks such as checking for property existence (`has`, `hasAll`), type coercion (`arrayify`), inspecting constructors (`hasConstructor`), retrieving property descriptors (`getDescriptor`), and managing inheritance and property copying between objects (`copyDescriptor`, `copy`, `inherit`). The library's focus is on lower-level prototype manipulation, which was more common in pre-ES6 JavaScript class patterns, though its utilities remain functional for modern class syntax when deeper introspection or direct prototype modification is required. It typically follows a stable, low-cadence release cycle given its foundational utility nature. A key differentiator is its explicit focus on descriptors and direct prototype manipulation, offering fine-grained control over object properties and inheritance chains beyond typical `Object.assign` or spread operator usage. It is primarily a CommonJS module built for Node.js environments from version 0.10.0 and up.

npm install class-utils
INSTALL
IMPORT
SIG · CLASS-UTILS
C
class-utils
devopsjavascriptv0.0.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cu
const cu = require('class-utils');
import cu from 'class-utils';
This package is primarily a CommonJS module. Direct ES Module imports will typically fail without a compatible bundler or transpilation setup.
has
const { has } = require('class-utils');
import { has } from 'class-utils';
The default CommonJS export is an object containing all utility methods. Individual methods can be destructured directly from the `require` call.
copyDescriptor
const cu = require('class-utils'); cu.copyDescriptor(targetObj, sourceObj, 'methodName');
Individual utility functions are exposed as methods on the main exported object.

Demonstrates importing the class-utils library and using `copyDescriptor` to transfer a property descriptor from one object's prototype to another.

const cu = require('class-utils'); function App() {} Object.defineProperty(App.prototype, 'count', { get: function() { return Object.keys(this).length; } }); const obj = {}; cu.copyDescriptor(obj, App.prototype, 'count'); console.log(Object.getOwnPropertyDescriptor(obj, 'count')); // Expected output: { get: [Function], set: undefined, enumerable: false, configurable: false }
Debug
Known issues
gotchaThis package is a CommonJS module and does not provide native ES Module (ESM) exports. Attempting to use `import` statements directly in an ESM context will likely result in errors unless a bundler or transpiler (like Webpack or Babel) is configured to handle CJS imports.
fix
Use `const cu = require('class-utils');` for Node.js projects or ensure your build setup correctly transpiles CommonJS for browser or ESM environments.
affects: >=0.1.0
gotchaThe package targets older Node.js versions (>=0.10.0), which means its internal implementation may not leverage modern JavaScript features (e.g., native ES6 classes, async/await). While functional, newer syntax or idioms might not be reflected.
fix
Be aware that the library's design reflects older JavaScript paradigms. Integrate carefully with modern class syntax if deep prototype manipulation is not your primary goal.
affects: <1.0.0
gotchaThe utilities primarily interact with JavaScript's prototype chain and property descriptors. Developers unfamiliar with these concepts, especially when primarily working with ES6 `class` syntax, might find the behavior non-intuitive or encounter unexpected results if not used carefully.
fix
Familiarize yourself with JavaScript's object prototypes and property descriptors (e.g., `Object.defineProperty`, `Object.getOwnPropertyDescriptor`) to fully understand the library's capabilities and implications.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: class_utils_1.default is not a function
Attempting to import `class-utils` using an ES Module `import` statement in an environment that expects CommonJS exports as a default.
fix
Change your import statement to `const cu = require('class-utils');`
TypeError: cu.someMethod is not a function
The imported `cu` object does not have the specified method, or `class-utils` was not correctly imported, resulting in `cu` being undefined or an unexpected value.
fix
Verify the method name is correct according to the API (`cu.has`, `cu.copyDescriptor`, etc.) and ensure `const cu = require('class-utils');` executed without error.
Upgrade
Version history
0.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
2
Resources
class-utils — npm install class-utils · libregistry