
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
custom-decorators
Advanced tools
[](https://www.npmjs.com/package/custom-decorators) [](https://www.npmjs.com/package/custom-decorators)
Easily extend and enhance existing code using a standard decorator syntax.
The extension plugin is written following the style of Koa Middleware
.
import custom from 'custom-decorators';
class ClassA {
// Just add a `@custom` decorator and the extension name.
@custom('ClassA.method')
// No need to modify something for the function
async method(name) {
console.log(`hello ${name}`);
}
}
// Add a middleware to extend the method
custom('ClassA.method', async function(context, next) {
// Get the arguments from the context
const { args } = context;
console.log(this, 'before', args[0]);
await next();
console.log(this, 'after', args[0]);
})
const instancea = new ClassA();
// invoke the original method as usual
instancea.method('world');
/* output
ClassA {} before world
hello world
ClassA {} after world
*/
async
and sync
functions depending on your declaration.class ClassA {
@custom('ClassA.method')
method(name) {
console.log(`hello ${name}`);
}
}
// Note that the original function is synchronous, so the plugin function should also be sync.
// DO NOT add the `async` keyword.
custom('ClassA.method', function(context, next) {
const { args } = context;
console.log(this, 'before', args[0]);
next();
console.log(this, 'after', args[0]);
})
class ClassA {
@custom('ClassA.method')
async get(name) {
return `hello ${name}`;
}
}
// Get & modify the return value
custom('ClassA.method', async function(context, next) {
const returnValue = await next();
return `before ${returnValue} after`;
})
const instancea = new ClassA();
console.log(instancea.get('world'));
/* output
before hello world after
*/
const PRIVATE_EXTENSION = Symbol('private_extension');
class ClassA {
@custom(PRIVATE_EXTENSION)
async method(name) {
console.log(`hello ${name}`);
}
}
custom(PRIVATE_EXTENSION, async function(context, next) {
// code gos here
})
Copyright (c) 2024-present, Zhoukekestar
FAQs
[](https://www.npmjs.com/package/custom-decorators) [](https://www.npmjs.com/package/custom-decorators)
The npm package custom-decorators receives a total of 0 weekly downloads. As such, custom-decorators popularity was classified as not popular.
We found that custom-decorators demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.