1.0.0 • Published 2 years ago

memoize-pure v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Install

$ npm i memoize-pure

API

Table of Contents

memoize

src/index.ts:16-26

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

Parameters

  • fn any The function to memoize
  • map A map object to use as memory (optional, default Object.create(null))

Returns any The memoized function

memoizeDebug

src/index.ts:48-89

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' }

Parameters

  • fn any The function to memoize
  • map (optional, default Object.create(null))
  • threshold (optional, default Infinity)

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

Contribute

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT © 2021 stagas