Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

class-utils

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

class-utils

Utils for working with JavaScript classes and prototype methods.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is class-utils?

The class-utils npm package provides utilities for working with ES6 classes and prototype functions. It includes methods for adding static and prototype methods, implementing mixins, and other class-related utilities.

What are class-utils's main functionalities?

Adding static methods

This feature allows you to add static methods to a class. The code sample demonstrates adding a static method called 'staticMethod' to 'MyClass' using class-utils.

const cu = require('class-utils');
class MyClass {}
cu.static(MyClass, { staticMethod: function() { return 'Static method'; } });
console.log(MyClass.staticMethod());

Adding prototype methods

This feature enables the addition of prototype methods to a class. The example shows how to add an instance method called 'instanceMethod' to 'MyClass' using class-utils.

const cu = require('class-utils');
class MyClass {}
cu.proto(MyClass, { instanceMethod: function() { return 'Instance method'; } });
let obj = new MyClass();
console.log(obj.instanceMethod());

Implementing mixins

This feature supports the implementation of mixins to extend class functionalities. The code sample illustrates adding a mixin method called 'mixinMethod' to 'MyClass' using a mixin function.

const cu = require('class-utils');
function mixin(source) { source.mixinMethod = function() { return 'Mixin method'; }; }
class MyClass {}
cu.mixin(MyClass, mixin);
let obj = new MyClass();
console.log(obj.mixinMethod());

Other packages similar to class-utils

Keywords

FAQs

Package last updated on 01 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc