
Product
Rust Support Now in Beta
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.
decoration-helper
Advanced tools
A tiny library to help decorate functions or classes in the ugly messy pre-standardized decorator spec era.
This is a absolutely tiny library to help decorate functions or classes in a prettier way in the ugly messy pre-standardized decorator spec era of Javascript.
Features:
decorate(...).with(fn)
apply(...).to(fn)
pipe(...)(fn)
and compose(...)(fn)
included.If you're here, you already know.
yarn add decoration-helper
To achieve this
@inject('app', 'auth')
@withRouter
@observer
function tomato() {
console.log("tomato");
}
export default tomato;
you write this:
import { apply } from 'decoration-helper';
function tomato() {
console.log("tomato");
}
export default apply(
inject('app', 'auth'),
withRouter,
observer
).to(tomato);
or alternatively this, if you prefer:
import { decorate } from 'decoration-helper';
function tomato() {
console.log("tomato");
}
export default decorate(tomato).with(
observer,
withRouter,
inject('app', 'auth')
);
Note: The order is not reversed when using decorate(obj).with(...decorators)
pipe()
and compose()
The proper functional approach would be to use pipe()
and compose()
as described by
Eric Elliot.
This post has
more details about it.
// Analogous to decorate(fn).with(...);
import { pipe } from 'decoration-helper';
function tomato() {
console.log("tomato");
}
export default pipe(
observer,
withRouter,
inject('app', 'auth')
)(tomato);
// Analogous to apply(...).to(fn);
import { compose } from 'decoration-helper';
function tomato() {
console.log("tomato");
}
export default compose(
inject('app', 'auth'),
withRouter,
observer
)(tomato);
MIT
FAQs
A tiny library to help decorate functions or classes in the ugly messy pre-standardized decorator spec era.
We found that decoration-helper 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.
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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.