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

mimic-function

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mimic-function

Make a function mimic another one

  • 5.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source
mimic-function logo

Make a function mimic another one

Useful when you wrap a function in another function and you would like to preserve the original name and other properties.

Install

npm install mimic-function

Usage

import mimicFunction from 'mimic-function';

function foo() {}
foo.unicorn = '🦄';

function wrapper() {
	return foo();
}

console.log(wrapper.name);
//=> 'wrapper'

mimicFunction(wrapper, foo);

console.log(wrapper.name);
//=> 'foo'

console.log(wrapper.unicorn);
//=> '🦄'

console.log(String(wrapper));
//=> '/* Wrapped with wrapper() */\nfunction foo() {}'

API

mimicFunction(to, from, options?)

Modifies the to function to mimic the from function. Returns the to function.

name, displayName, and any other properties of from are copied. The length property is not copied. Prototype, class, and inherited properties are copied.

to.toString() will return the same as from.toString() but prepended with a Wrapped with to() comment.

to

Type: Function

Mimicking function.

from

Type: Function

Function to mimic.

options

Type: object

ignoreNonConfigurable

Type: boolean
Default: false

Skip modifying non-configurable properties instead of throwing an error.

  • rename-fn - Rename a function
  • keep-func-props - Wrap a function without changing its name and other properties

Keywords

FAQs

Package last updated on 14 Mar 2024

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