
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
decorator-builder
Advanced tools
Easily create decorators for multiple and flexible purposes
npm i decorator-builder
Just create your new decorator
const MyDecorator = createClassDecorator();
And then, apply it to your class!
@MyDecorator()
class MyClass {}
The generated decorator is also an Iterable, so, you can get access to every decorated class already loaded
for (const item of MyDecorator) {
// Target is the Class and args the arguments informed into the decorator
doABarrelRoll(item.target, item.args);
}
You can also create method decorators:
const MyDecorator = createMethodDecorator();
class MyClass {
@MyDecorator()
myMethod() {
}
}
for (const item of MyDecorator) {
// Target is the Prototype, name is the method name, descriptor the method descriptor, and args the arguments informed into the decorator
doABarrelRoll(item.target, item.name, item.descriptor, item.args);
}
Property decorators:
const MyDecorator = createPropertyDecorator();
class MyClass {
@MyDecorator()
myProperty: string;
}
for (const item of MyDecorator) {
// Target is the Prototype, name is the property name, and args the arguments informed into the decorator
doABarrelRoll(item.target, item.name, item.args);
}
And parameters decorators:
const MyDecorator = createParameterDecorator();
class MyClass {
myMethod(@MyDecorator() arg: string) {}
}
for (const item of MyDecorator) {
// Target is the Prototype, name is the method name, index the parameter index, and args the arguments informed into the decorator
doABarrelRoll(item.target, item.name, item.index, item.args);
}
If you want to create a decorator that receives parameters, you can inform it in it's creation through a function template:
// It works with every type of decorator
const MyDecorator = createMethodDecorator<(value: number, name: string) => void>();
You can also inform a callback to be called at every decorator appliance
const MyDecorator = createMethodDecorator((item) => {
console.log(item.name);
})
This package also provides a helper function if you want to apply some modification into a class. This is useful to apply in the callback of the decorator:
wrapClass(item.target, (self: SomeClassExtended, a: string, b: number) => {
self.c = a + b;
})
There is a helper function too so you can wrap methods. This function will directly replace a method on the prototype or the instance, whenever is provided:
// Replaces the method prototype
wrapMethod(SomeClass.prototype, 'method', (previousVersion, paramsOfTheMethod) => previousVersion(paramsOfTheMethod) + 2);
// Replaces just the instance method
wrapMethod(instance, 'method', (previousVersion, paramsOfTheMethod) => previousVersion(paramsOfTheMethod) + 3);
Licensed under MIT.
0.2.4
FAQs
Easily create decorators for multiple and flexible purposes
The npm package decorator-builder receives a total of 2 weekly downloads. As such, decorator-builder popularity was classified as not popular.
We found that decorator-builder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.