decorate a function, forwarding properties


302.0.14 years ago4 years agoMinified + gzip package size for @npm/decorate in KB



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


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.



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.