Package Exports
- keep-func-props
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (keep-func-props) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Wrap a function without changing its name, length and other properties.
Function wrappers are commonly used in functional programming. They take a function as input and return it wrapped. Examples include memoizing or ensuring a function is only called once.
However those wrappers return a new function which means the original
function's name
, length
and other properties are lost. This module
enhances a function wrapper to keep those properties.
const keepFuncProps = require('keep-func-props')
const memoize = require('lodash/memoize')
const betterMemoize = keepFuncProps(memoize)
const anyFunction = function() {
return true
}
// Function name is `memoized`
console.log(memoize(anyFunction))
// Function name is `anyFunction`
console.log(betterMemoize(anyFunction))
Installation
npm install keep-func-props
Usage
const keepFuncProps = require('keep-func-props')
const functionWrapper = function(func) {
return (...args) => func(...args)
}
// `betterWrapper` is like `functionWrapper` but it keeps the function
// properties
const betterWrapper = keepFuncProps(functionWrapper)
The function wrapper must:
- take a function as first argument
- take additional arguments (e.g. an options object)
- return a new function
Each of those requirements is optional.
Related projects
If you want to modify a function that is not a function wrapper, check out
mimic-fn
.