source: trip-planner-front/node_modules/mimic-fn/readme.md@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1# mimic-fn [![Build Status](https://travis-ci.org/sindresorhus/mimic-fn.svg?branch=master)](https://travis-ci.org/sindresorhus/mimic-fn)
2
3> Make a function mimic another one
4
5Useful when you wrap a function in another function and like to preserve the original name and other properties.
6
7
8## Install
9
10```
11$ npm install mimic-fn
12```
13
14
15## Usage
16
17```js
18const mimicFn = require('mimic-fn');
19
20function foo() {}
21foo.unicorn = '🦄';
22
23function wrapper() {
24 return foo();
25}
26
27console.log(wrapper.name);
28//=> 'wrapper'
29
30mimicFn(wrapper, foo);
31
32console.log(wrapper.name);
33//=> 'foo'
34
35console.log(wrapper.unicorn);
36//=> '🦄'
37```
38
39
40## API
41
42It will copy over the properties `name`, `length`, `displayName`, and any custom properties you may have set.
43
44### mimicFn(to, from)
45
46Modifies the `to` function and returns it.
47
48#### to
49
50Type: `Function`
51
52Mimicking function.
53
54#### from
55
56Type: `Function`
57
58Function to mimic.
59
60
61## Related
62
63- [rename-fn](https://github.com/sindresorhus/rename-fn) - Rename a function
64- [keep-func-props](https://github.com/ehmicky/keep-func-props) - Wrap a function without changing its name, length and other properties
65
66
67## License
68
69MIT © [Sindre Sorhus](https://sindresorhus.com)
Note: See TracBrowser for help on using the repository browser.