+15
| /** | ||
| * Make a function mimic another one. It will copy over the properties `name`, `length`, `displayName`, and any custom properties you may have set. | ||
| * | ||
| * @param to - Mimicking function. | ||
| * @param from - Function to mimic. | ||
| * @returns The modified `to` function. | ||
| */ | ||
| export default function mimicFn< | ||
| ArgumentsType extends unknown[], | ||
| ReturnType, | ||
| FunctionType extends (...arguments: ArgumentsType) => ReturnType | ||
| >( | ||
| to: (...arguments: ArgumentsType) => ReturnType, | ||
| from: FunctionType | ||
| ): FunctionType; |
+6
-3
| 'use strict'; | ||
| module.exports = (to, from) => { | ||
| // TODO: use `Reflect.ownKeys()` when targeting Node.js 6 | ||
| for (const prop of Object.getOwnPropertyNames(from).concat(Object.getOwnPropertySymbols(from))) { | ||
| const mimicFn = (to, from) => { | ||
| for (const prop of Reflect.ownKeys(from)) { | ||
| Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop)); | ||
@@ -10,1 +10,4 @@ } | ||
| }; | ||
| module.exports = mimicFn; | ||
| module.exports.default = mimicFn; |
+8
-6
| { | ||
| "name": "mimic-fn", | ||
| "version": "1.2.0", | ||
| "version": "2.0.0", | ||
| "description": "Make a function mimic another one", | ||
@@ -13,9 +13,10 @@ "license": "MIT", | ||
| "engines": { | ||
| "node": ">=4" | ||
| "node": ">=6" | ||
| }, | ||
| "scripts": { | ||
| "test": "xo && ava" | ||
| "test": "xo && ava && tsd-check" | ||
| }, | ||
| "files": [ | ||
| "index.js" | ||
| "index.js", | ||
| "index.d.ts" | ||
| ], | ||
@@ -38,5 +39,6 @@ "keywords": [ | ||
| "devDependencies": { | ||
| "ava": "*", | ||
| "xo": "*" | ||
| "ava": "^1.3.1", | ||
| "tsd-check": "^0.3.0", | ||
| "xo": "^0.24.0" | ||
| } | ||
| } |
+1
-1
@@ -46,3 +46,3 @@ # mimic-fn [](https://travis-ci.org/sindresorhus/mimic-fn) | ||
| It will modify `to` and return it. | ||
| Modifies the `to` function and returns it. | ||
@@ -49,0 +49,0 @@ #### to |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
3582
17.25%5
25%24
200%0
-100%3
50%