Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
The `unherit` npm package is designed to create a factory for customizable classes. It allows you to inherit from a class and then further customize the subclass. This can be particularly useful in scenarios where you want to extend or modify the behavior of existing classes without directly modifying their source code. It's commonly used in the context of creating customizable components or plugins.
Creating a customizable subclass
This feature allows you to create a subclass from a superclass and then customize that subclass. It's useful for extending existing classes in a modular and reusable way.
const unherit = require('unherit');
const Super = require('./some-super-class');
const Custom = unherit(Super);
// Now, `Custom` can be further extended or modified without affecting `Super`.
Similar to `unherit`, `class-extend` allows you to extend classes in Node.js. It provides a simple way to inherit from existing classes and add or override methods. The main difference is in the API and the way you use it to extend classes.
This package offers functionality to extend classes as well, but with a focus on creating extendable constructors. It's similar to `unherit` in its goal to facilitate class extension and customization, but differs in its approach and specific use cases.
Create a subclass that can be modified without affecting the super class.
This is a tiny package lets you create a subclass, that can be modified, without affecting the super class.
Not often! You might have some weird cases though.
This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:
npm install unherit
In Deno with esm.sh
:
import {unherit} from 'https://esm.sh/unherit@3'
In browsers with esm.sh
:
<script type="module">
import {unherit} from 'https://esm.sh/unherit@3?bundle'
</script>
import {EventEmitter} from 'node:events'
import {unherit} from 'unherit'
// Create a private class which acts just like `EventEmitter`.
const Emitter = unherit(EventEmitter)
Emitter.prototype.defaultMaxListeners = 0
// Now, all instances of `Emitter` have `0` maximum listeners, without affecting
// other `EventEmitter`s.
new Emitter().defaultMaxListeners === 0 // => true
new EventEmitter().defaultMaxListeners === undefined // => true
new Emitter() instanceof EventEmitter // => true
This package exports the identifier unherit
.
There is no default export.
unherit(Super)
Subclass Super
.
This package is fully typed with TypeScript. It exports no additional types.
This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.
Yes please! See How to Contribute to Open Source.
This package is safe.
FAQs
Create a subclass that can be modified without affecting the super class
The npm package unherit receives a total of 376,318 weekly downloads. As such, unherit popularity was classified as popular.
We found that unherit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.