![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Generate a destruction method which clean's up and destroys all references on the instance
Demolish is a small module which helps you clean, release and destroy your created instances.
This module is intended for Node.js and Browserify usage and can be installed using:
npm install --save demolish
The module is exported as a function and be required as following:
'use strict';
var demolish = require('demolish');
The demolish
function returns a function which will destroy the specified
properties from your instance.
function Foo() {
this.bar = 1;
this.banana = new Banana();
}
Foo.prototype.destroy = demolish('bar banana');
In the example above we've created a new destroy
method on our Foo
class.
Once the method is called it will set the bar
property to null
and check if
banana
also has a destroy
method, if so, it will call that method and set
the property to null
after the execution.
After everything is cleaned up we will emit a destroy
event if there is an
emit
method available.
The destroy
method will automatically prevent double execution by checking if
the first supplied property is still active on the prototype. So in the example
above it will check if bar
is not null
.
But nulling objects and destroying things you've set on an instance might not be
enough. Sometimes you need a bit more and for those cases we have the additional
before
and after
hooks. These hooks can be specified in the options:
Foo.prototype.destroy = demolish('bar banana', {
before: 'clear',
after: ['removeAllListeners', function () {
// things
}]
});
In the example above you see all the supported styles. If you supply a string
we assume that it's a function on the prototype that needs to be executed in order
to clean up things correctly. If you need to run multiple tasks you can supply
an array with strings. In addition to strings we also support functions, these
functions will be called with their this
value set to the instance of the class
where destroy
works.
So in the example above the execution flow is the following:
destroy
has already been called, if not, continue to step 2.destroy
event, where possible.MIT
FAQs
Generate a destruction method which clean's up and destroys all references on the instance
The npm package demolish receives a total of 296 weekly downloads. As such, demolish popularity was classified as not popular.
We found that demolish demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.