Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stagas/memoize-pure
low footprint memoize for just pure sync functions with scalar arguments
https://github.com/stagas/memoize-pure
memoize
Last synced: 13 days ago
JSON representation
low footprint memoize for just pure sync functions with scalar arguments
- Host: GitHub
- URL: https://github.com/stagas/memoize-pure
- Owner: stagas
- Created: 2021-12-03T04:58:08.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-03T06:11:56.000Z (almost 3 years ago)
- Last Synced: 2024-10-13T17:38:52.165Z (about 1 month ago)
- Topics: memoize
- Language: TypeScript
- Homepage:
- Size: 201 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
memoize-pure
low footprint memoize for just pure sync functions with scalar arguments
🔧 Install
· 🧩 Example
· 📜 API docs
· 🔥 Releases
· 💪🏼 Contribute
· 🖐️ Help***
## Install
```sh
$ npm i memoize-pure
```## API
#### Table of Contents
* [memoize](#memoize)
* [Parameters](#parameters)
* [memoizeDebug](#memoizedebug)
* [Parameters](#parameters-1)### memoize
[src/index.ts:16-26](https://github.com/stagas/memoize-pure/blob/b06373fb2b76ba49c486d0189e8c4a31d728276d/src/index.ts#L16-L26 "Source code on GitHub")
Memoize a function.
```ts
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](https://github.com/stagas/memoize-pure/blob/b06373fb2b76ba49c486d0189e8c4a31d728276d/src/index.ts#L48-L89 "Source code on GitHub")
Debug memoize a function.
```ts
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](https://github.com/stagas/memoize-pure/fork) or
[edit](https://github.dev/stagas/memoize-pure) and submit a PR.All contributions are welcome!
## License
MIT © 2021
[stagas](https://github.com/stagas)