@npm/decorate

decorate a function, forwarding properties

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
20Dec 10, 2020May 6, 2017Minified + gzip package size for @npm/decorate in KB

Readme

@npm/decorate

Decorate a function, forwarding properties.

const decorate = require('@npm/decorate')

function myFunction () {
  return 1
}
myFunction.bloo = 3

const decorated = decorate(myFunction, (...args) => {
  return myFunction(...args) + 1
})

console.log(decorated.name) // myFunction
console.log(decorated.bloo) // 3
console.log(decorated())    // 2

API

decorate(inner, wrapper) -> Function

Forward all properties from inner to a merged function that calls wrapper.

decorate.undecorate(Function) -> Function | Null

Return the inner function of a decorated function. or null.

decorate.decorations(Function) -> Iterator<Function>

Return an iterator that yields all decoration wrappers of a given function in order.

License

ISC

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.