5.0.0 • Published 5 months ago

mimic-fn v5.0.0

Weekly downloads
28,143,370
License
MIT
Repository
github
Last release
5 months ago

Make a function mimic another one

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

Install

$ npm install mimic-fn

Usage

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);
//=> '🦄'

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.

Related


memfree-min@huyhpham/rn-linearchetype-librarycomponennentteasy-select-rnvuedragdropuploadimagesreact-native-bluetooth2killi8n-react-native-fast-imagepipihomern-send-smsspecify-importsbabel-specify-importscad-cli@icanpm/api-master@arisageha/react-lazyload@arisageha/react-lazyload-fix@oneplanetcrowd/developersfoshata-markdownrdclr-boilerplate@cashremit/cr-streamline-icons@almeidaa/msreact-native-template-rfbaseairscanairscan-examplebb-chatreact-native-esc-pos-sahaab@borisovart/atol-kkt-module@frxf/frxfdeneme323112@texttree/demo-bsa-reference-rcl@fundefund/funde_ck@ntt_app/react-native-custom-notificationreact-native-custom-text-hwjamesreact-native-covid-sdkgql_din_modbitgetreact-native-thanh-toast-librarymutasi-bca@jttechnic/interpreter@thanhnguyen14797/react-native-thanh-toast-library@l1nyanm1ng/react-picture-viewerauto-extractcthpb-plugin-social@iobroker-community-adapters/iobroker.device-watcher@olivervorasai/slidermysql-formatreact-native-printer-brothersrn-pdf-reader-offlinecbmis-ai-toolbox@newhorizon-tech/dd-npm-package-templatereact-native-shekhar-bridge-testcogoportutilsukor-remasterdyx-reactlevibestliblevibestlib2levilibtest19levilibtest24levilibtest25levilibtest26levilibtest27levilibtest28levilibtest29talent-to-vite-cliwilscanner@oiti/documentoscopy-react-nativejs4cytoscape@respondea/cordova-plugin-v-inappbrowser@mink-opn/build-tokensquoc-testreact-native-slider-kfunblock-block-save-variables@infinitebrahmanuniverse/nolb-mim@prodam/prodam-typescclibyarntest@saaspe/componentshyperpass-sdkplginshamsi-date-nowexpand-react-bridgeopea-bootstraapluminos-ui-coresklif-ui-kitsklif-api@everything-registry/sub-chunk-2170iqra-calculatorjawwy-sdkjawwy_gamification_release@314oner_npm/universal-components-libraryreact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgp149-table@rabailriaz/hisaab-web-portalsklif-uircf-tea-testnetreact-native-jawwy_samplecode-msi-simple_calculator123
5.0.0

5 months ago

4.0.0

3 years ago

3.1.0

4 years ago

3.0.0

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.2.0

6 years ago

1.1.0

7 years ago

1.0.0

8 years ago