Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
decorator-builder
Advanced tools
Changelog
0.2.4
Readme
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.
FAQs
Easily create decorators for multiple and flexible purposes
The npm package decorator-builder receives a total of 15 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.