CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
readme.md81 linesDownload Raw Back to mimic-function
1<picture>2	<source media="(prefers-color-scheme: dark)" srcset="media/logo_dark.svg">3	<img alt="mimic-function logo" src="media/logo.svg" width="400">4</picture>5<br>6 7> Make a function mimic another one8 9Useful when you wrap a function in another function and you would like to preserve the original name and other properties.10 11## Install12 13```sh14npm install mimic-function15```16 17## Usage18 19```js20import mimicFunction from 'mimic-function';21 22function foo() {}23foo.unicorn = '๐Ÿฆ„';24 25function wrapper() {26	return foo();27}28 29console.log(wrapper.name);30//=> 'wrapper'31 32mimicFunction(wrapper, foo);33 34console.log(wrapper.name);35//=> 'foo'36 37console.log(wrapper.unicorn);38//=> '๐Ÿฆ„'39 40console.log(String(wrapper));41//=> '/* Wrapped with wrapper() */\nfunction foo() {}'42```43 44## API45 46### mimicFunction(to, from, options?)47 48Modifies the `to` function to mimic the `from` function. Returns the `to` function.49 50`name`, `displayName`, and any other properties of `from` are copied. The `length` property is not copied. Prototype, class, and inherited properties are copied.51 52`to.toString()` will return the same as `from.toString()` but prepended with a `Wrapped with to()` comment.53 54#### to55 56Type: `Function`57 58Mimicking function.59 60#### from61 62Type: `Function`63 64Function to mimic.65 66#### options67 68Type: `object`69 70##### ignoreNonConfigurable71 72Type: `boolean`\73Default: `false`74 75Skip modifying [non-configurable properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor#Description) instead of throwing an error.76 77## Related78 79- [rename-fn](https://github.com/sindresorhus/rename-fn) - Rename a function80- [keep-func-props](https://github.com/ehmicky/keep-func-props) - Wrap a function without changing its name and other properties81 
basant307/AI_Governance_Project ยท CoolFace