Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

keep-func-props

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keep-func-props

Wrap a function without changing its name, length and other properties

  • 1.0.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
122K
increased by3.18%
Maintainers
1
Weekly downloads
 
Created
Source

downloads last commit Coverage Status travis node Gitter

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.

If you want to modify a function that is not a function wrapper, check out mimic-fn.

Keywords

FAQs

Package last updated on 05 Mar 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc