Utils for working with JavaScript classes and prototype methods.
Installations
npm install class-utils
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=0.10.0
Node Version
9.1.0
NPM Version
5.6.0
Score
99
Supply Chain
95.2
Quality
77
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
jonschlinkert
Download Statistics
Total Downloads
4,298,033,226
Last Day
1,875,679
Last Week
11,308,515
Last Month
44,550,204
Last Year
570,081,469
GitHub Statistics
MIT License
19 Stars
50 Commits
7 Forks
3 Watchers
1 Branches
4 Contributors
Updated on Dec 28, 2023
Bundle Size
8.76 kB
Minified
2.43 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.3.6
Package Id
class-utils@0.3.6
Size
5.25 kB
NPM Version
5.6.0
Node Version
9.1.0
Published on
Jan 11, 2018
Total Downloads
Cumulative downloads
Total Downloads
4,298,033,226
Last Day
-12.9%
1,875,679
Compared to previous day
Last Week
4.4%
11,308,515
Compared to previous week
Last Month
36.9%
44,550,204
Compared to previous month
Last Year
-22.4%
570,081,469
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
4
class-utils

Utils for working with JavaScript classes and prototype methods.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install
Install with npm:
1$ npm install --save class-utils
Usage
1var cu = require('class-utils');
API
.has
Returns true if an array has any of the given elements, or an object has any of the give keys.
Params
obj
{Object}val
{String|Array}returns
{Boolean}
Example
1cu.has(['a', 'b', 'c'], 'c'); 2//=> true 3 4cu.has(['a', 'b', 'c'], ['c', 'z']); 5//=> true 6 7cu.has({a: 'b', c: 'd'}, ['c', 'z']); 8//=> true
.hasAll
Returns true if an array or object has all of the given values.
Params
val
{Object|Array}values
{String|Array}returns
{Boolean}
Example
1cu.hasAll(['a', 'b', 'c'], 'c'); 2//=> true 3 4cu.hasAll(['a', 'b', 'c'], ['c', 'z']); 5//=> false 6 7cu.hasAll({a: 'b', c: 'd'}, ['c', 'z']); 8//=> false
.arrayify
Cast the given value to an array.
Params
val
{String|Array}returns
{Array}
Example
1cu.arrayify('foo'); 2//=> ['foo'] 3 4cu.arrayify(['foo']); 5//=> ['foo']
.hasConstructor
Returns true if a value has a contructor
Params
value
{Object}returns
{Boolean}
Example
1cu.hasConstructor({}); 2//=> true 3 4cu.hasConstructor(Object.create(null)); 5//=> false
.nativeKeys
Get the native ownPropertyNames
from the constructor of the given object
. An empty array is returned if the object does not have a constructor.
Params
obj
{Object}: Object that has aconstructor
.returns
{Array}: Array of keys.
Example
1cu.nativeKeys({a: 'b', b: 'c', c: 'd'}) 2//=> ['a', 'b', 'c'] 3 4cu.nativeKeys(function(){}) 5//=> ['length', 'caller']
.getDescriptor
Returns property descriptor key
if it's an "own" property of the given object.
Params
obj
{Object}key
{String}returns
{Object}: Returns descriptorkey
Example
1function App() {}
2Object.defineProperty(App.prototype, 'count', {
3 get: function() {
4 return Object.keys(this).length;
5 }
6});
7cu.getDescriptor(App.prototype, 'count');
8// returns:
9// {
10// get: [Function],
11// set: undefined,
12// enumerable: false,
13// configurable: false
14// }
.copyDescriptor
Copy a descriptor from one object to another.
Params
receiver
{Object}provider
{Object}name
{String}returns
{Object}
Example
1function App() {}
2Object.defineProperty(App.prototype, 'count', {
3 get: function() {
4 return Object.keys(this).length;
5 }
6});
7var obj = {};
8cu.copyDescriptor(obj, App.prototype, 'count');
.copy
Copy static properties, prototype properties, and descriptors from one object to another.
Params
receiver
{Object}provider
{Object}omit
{String|Array}: One or more properties to omitreturns
{Object}
.inherit
Inherit the static properties, prototype properties, and descriptors from of an object.
Params
receiver
{Object}provider
{Object}omit
{String|Array}: One or more properties to omitreturns
{Object}
.extend
Returns a function for extending the static properties, prototype properties, and descriptors from the Parent
constructor onto Child
constructors.
Params
Parent
{Function}: Parent ctorextend
{Function}: Optional extend function to handle custom extensions. Useful when updating methods that require a specific prototype.Child
{Function}: Child ctorproto
{Object}: Optionally pass additional prototype properties to inherit.returns
{Object}
Example
1var extend = cu.extend(Parent); 2Parent.extend(Child); 3 4// optional methods 5Parent.extend(Child, { 6 foo: function() {}, 7 bar: function() {} 8});
.bubble
Bubble up events emitted from static methods on the Parent ctor.
Params
Parent
{Object}events
{Array}: Event names to bubble up
About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
1$ npm install && npm test
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
1$ npm install -g verbose/verb#dev verb-generate-readme && verb
Related projects
You might also be interested in these projects:
- define-property: Define a non-enumerable property on an object. Uses Reflect.defineProperty when available, otherwise Object.defineProperty. | homepage
- delegate-properties: Deep-clone properties from one object to another and make them non-enumerable, or make existing properties… more | homepage
- is-descriptor: Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for… more | homepage
Contributors
Commits | Contributor |
---|---|
34 | jonschlinkert |
8 | doowb |
2 | wtgtybhertgeghgtwtg |
Author
Jon Schlinkert
License
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on January 11, 2018.

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 2/27 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 6 are checked with a SAST tool
Score
3
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to class-utils
@stdlib/utils-native-class
Determine the specification defined classification of an object.
error-class-utils
Properly create error classes
@stdlib/utils-constructor-name
Determine the name of a value's constructor.
@erudilabs/merge-class-utils
Utility function to efficiently merge Tailwind CSS classes in JS without style conflicts.