mimic-fn
- Version 5.0.0
- Published
- 8.18 kB
- No dependencies
- MIT license
Install
npm i mimic-fn
yarn add mimic-fn
pnpm add mimic-fn
Overview
Make a function mimic another one
Index
Functions
Interfaces
Functions
function mimicFunction
mimicFunction: < ArgumentsType extends unknown[], ReturnType, FunctionType extends (...arguments: ArgumentsType) => ReturnType>( to: (...arguments: ArgumentsType) => ReturnType, from: FunctionType, options?: Options) => FunctionType;
Modifies the
to
function to mimic thefrom
function. Returns theto
function.name
,displayName
, and any other properties offrom
are copied. Thelength
property is not copied. Prototype, class, and inherited properties are copied.to.toString()
will return the same asfrom.toString()
but prepended with aWrapped with to()
comment.Parameter to
Mimicking function.
Parameter from
Function to mimic.
Returns
The modified
to
function.Example 1
import mimicFunction from 'mimic-fn';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);//=> '🦄'
Interfaces
interface Options
interface Options {}
property ignoreNonConfigurable
readonly ignoreNonConfigurable?: boolean;
Skip modifying [non-configurable properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor#Description) instead of throwing an error.
false
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (3)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/mimic-fn
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/mimic-fn)
- HTML<a href="https://www.jsdocs.io/package/mimic-fn"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3051 ms. - Missing or incorrect documentation? Open an issue for this package.