{"id":15095,"library":"class-utils","title":"Class Utils","description":"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.","status":"maintenance","version":"0.3.6","language":"javascript","source_language":"en","source_url":"https://github.com/jonschlinkert/class-utils","tags":["javascript","array","assign","class","copy","ctor","define","delegate","descriptor"],"install":[{"cmd":"npm install class-utils","lang":"bash","label":"npm"},{"cmd":"yarn add class-utils","lang":"bash","label":"yarn"},{"cmd":"pnpm add class-utils","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is primarily a CommonJS module. Direct ES Module imports will typically fail without a compatible bundler or transpilation setup.","wrong":"import cu from 'class-utils';","symbol":"cu","correct":"const cu = require('class-utils');"},{"note":"The default CommonJS export is an object containing all utility methods. Individual methods can be destructured directly from the `require` call.","wrong":"import { has } from 'class-utils';","symbol":"has","correct":"const { has } = require('class-utils');"},{"note":"Individual utility functions are exposed as methods on the main exported object.","symbol":"copyDescriptor","correct":"const cu = require('class-utils');\ncu.copyDescriptor(targetObj, sourceObj, 'methodName');"}],"quickstart":{"code":"const cu = require('class-utils');\n\nfunction App() {}\nObject.defineProperty(App.prototype, 'count', {\n  get: function() {\n    return Object.keys(this).length;\n  }\n});\n\nconst obj = {};\ncu.copyDescriptor(obj, App.prototype, 'count');\n\nconsole.log(Object.getOwnPropertyDescriptor(obj, 'count'));\n// Expected output: { get: [Function], set: undefined, enumerable: false, configurable: false }","lang":"javascript","description":"Demonstrates importing the class-utils library and using `copyDescriptor` to transfer a property descriptor from one object's prototype to another."},"warnings":[{"fix":"Use `const cu = require('class-utils');` for Node.js projects or ensure your build setup correctly transpiles CommonJS for browser or ESM environments.","message":"This 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"<1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Change your import statement to `const cu = require('class-utils');`","cause":"Attempting to import `class-utils` using an ES Module `import` statement in an environment that expects CommonJS exports as a default.","error":"TypeError: class_utils_1.default is not a function"},{"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.","cause":"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.","error":"TypeError: cu.someMethod is not a function"}],"ecosystem":"npm"}