-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.d.ts
36 lines (36 loc) · 1.15 KB
/
main.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Ensure a function `wrapper` so it does not change the `name` (or other
* properties) or functions passed to it as argument.
* A copy of that `wrapper` is returned.
*
* @example
* ```js
* // Any function wrapper works
* import memoize from 'lodash/memoize.js'
*
* const betterMemoize = keepFuncProps(memoize)
*
* const anyFunction = () => true
*
* // Function `name` and other properties are kept
* console.log(anyFunction) // `[Function: anyFunction]`
* console.log(memoize(anyFunction)) // `[Function: memoized]`
* console.log(betterMemoize(anyFunction)) // `[Function: anyFunction]`
*
* // Function body is kept when stringified
* console.log(String(anyFunction))
* // () => true
* console.log(String(memoize(anyFunction)))
* // function() {
* // var args = arguments,
* // key = resolver ? resolver.apply(this, args) : args[0],
* // cache = memoized.cache;
* // ...
* // }
* console.log(String(betterMemoize(anyFunction)))
* // /* Wrapped with memoized() *\/
* // () => true
* ```
*/
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
export default function keepFuncProps<T extends Function>(wrapper: T): T