
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
decorate-with-options
Advanced tools
npm install decorate-with-options --save
If your decorator function expects options, you can call it in many different ways(see examples of usage below).
I'm tired of having to remember how exactly I have to call each decorator in my code.
With this module you don't have this problem anymore. Just wrap your decorator once and call it whichever way you want!
Works for decorators and Higher Order Components(HoC).
1. Define your decorator. It should accept class(or function) as it's first argument and other options(non functions, see here why) as next arguments.
function myDecorator(Component, option1, option2) {
// ...
}
2. Wrap it in decorate-with-options
.
import decorateWithOptions from 'decorate-with-options';
export default decorateWithOptions(myDecorator);
function myDecorator(Component, option1, option2) {
// ...
}
3. Use it in your code in any of the following ways.
import myDecorator from './myDecorator';
/* As decorator */
// Simply apply it
@myDecorator
class Component {}
// Call it without options
@myDecorator()
class Component {}
// Call it with options
@myDecorator(option1, option2)
class Component {}
/* As HoC. Works with both classes and functions */
// Call it with Component
myDecorator(Component)
// Call it with Component and options
myDecorator(Component, option1, option2)
// Or the other way around
myDecorator(option1, option2, Component)
// Currying is supported
myDecorator(option1, option2)(Component)
How does this module determine that the class or a function is passed in?
With a simple (typeof arg === 'function')
check.
So don't pass functions in place of options. Use an object with properties instead. That's the only constraint.
E.g. don't do this:
// Don't do this
const someFunction = () => {};
@myDecorator(someFunction);
myDecorator(Component, someFunction);
myDecorator(someFunction, Component);
myDecorator(someFunction)(Component);
FAQs
Create decorator with options and universal signature
The npm package decorate-with-options receives a total of 0 weekly downloads. As such, decorate-with-options popularity was classified as not popular.
We found that decorate-with-options 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.