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.
babel-plugin-parameter-decorator
Advanced tools
Function parameter decorator transform plugin for babel v7, just like typescript.
Function parameter decorator transform plugin for babel v7, just like typescript parameter decorator
function validate(target, property, descriptor) {
const fn = descriptor.value;
descriptor.value = function (...args) {
const metadata = `meta_${property}`;
target[metadata].forEach(function (metadata) {
if (args[metadata.index] === undefined) {
throw new Error(`${metadata.key} is required`);
}
});
return fn.apply(this, args);
};
return descriptor;
}
function required(key) {
return function (target, propertyKey, parameterIndex) {
const metadata = `meta_${propertyKey}`;
target[metadata] = [
...(target[metadata] || []),
{
index: parameterIndex,
key
}
]
};
}
class Greeter {
constructor(message) {
this.greeting = message;
}
@validate
greet(@required('name') name) {
return "Hello " + name + ", " + this.greeting;
}
}
This package depends on @babel/plugin-proposal-decorators
.
npm install @babel/plugin-proposal-decorators babel-plugin-parameter-decorator -D
And the .babelrc
looks like:
{
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
"babel-plugin-parameter-decorator"
]
}
If you'd like to compile typescript files by babel, the file extensions .ts
or .tsx
expected, or we will get runtime error!
🎊 Hopefully this plugin would get along with typescript private/public
keywords in constructor
. For example,
@Factory
class Greeter {
private counter: Counter = this.sentinel.counter;
constructor(private greeting: string, @Inject(Sentinel) private sentinel: Sentinel) {
}
@validate
greet(@required('name') name: string) {
return "Hello " + name + ", " + this.greeting;
}
count() {
return this.counter.number;
}
}
And your .babelrc
looks like:
{
"presets": [
"@babel/preset-env",
"@babel/preset-typescript"
],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose" : true }],
"babel-plugin-parameter-decorator"
]
}
FAQs
Function parameter decorator transform plugin for babel v7, just like typescript.
We found that babel-plugin-parameter-decorator 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.
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.