low footprint memoize for just pure sync functions with scalar arguments
🔧 Install · 🧩 Example · 📜 API docs · 🔥 Releases · 💪🏼 Contribute · 🖐️ Help
$ npm i memoize-pure
Memoize a function.
const fn = memoize((a, b, c) => some_expensive_calls(a, b, c))
...
const result = fn(1, 2, 3) // => calls the inner function and saves arguments signature "1,2,3"
...
const result = fn(1, 2, 3) // => returns the memoized result immediately since "1,2,3" matches memory
fn
any The function to memoizemap
A map object to use as memory (optional, defaultObject.create(null)
)
Returns any The memoized function
Debug memoize a function.
const fn = memoizeDebug((a, b, c) => some_expensive_calls(a, b, c))
...
const result = fn(1, 2, 3) // => calls the inner function and saves arguments signature "1,2,3"
...
const result = fn(1, 2, 3) // => returns the memoized result immediately since "1,2,3" matches memory
fn.__memoizeTimesCalled__ // => 1
fn.__memoizeMap__ // => { '1,2,3': 'some result' }
fn
any The function to memoizemap
(optional, defaultObject.create(null)
)threshold
(optional, defaultInfinity
)
Returns any The memoized function including two properties:* __memoizeMap__
is the memory map of arguments and results
__memoizeTimesCalled__
is the count that the wrapped function has been called
All contributions are welcome!
MIT © 2021 stagas