Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
custom-decorators
Advanced tools
[![npm](https://img.shields.io/npm/v/custom-decorators.svg)](https://www.npmjs.com/package/custom-decorators) [![npm](https://img.shields.io/npm/dy/custom-decorators.svg)](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
[![npm](https://img.shields.io/npm/v/custom-decorators.svg)](https://www.npmjs.com/package/custom-decorators) [![npm](https://img.shields.io/npm/dy/custom-decorators.svg)](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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.