# @essentials/memoize-one

> A memoization algorithm that only caches the result of the latest set of arguments, where argument equality is determined via a provided equality function.

Latest version **1.1.0** (published 2020-06-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @essentials/memoize-one
pnpm add @essentials/memoize-one
yarn add @essentials/memoize-one
bun add @essentials/memoize-one
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-06-05 |
| First published | 2019-04-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Jared Lunde |
| Maintainers | jaredlunde |
| Keywords | memoize one, memoize, memo, fast memoize, fast memo, memo one |

## Links

- npm: https://www.npmjs.com/package/@essentials/memoize-one
- Repository: https://github.com/jaredLunde/essentials
- Homepage: https://github.com/jaredLunde/essentials/tree/master/packages/memoize-one#readme
- Issues: https://github.com/jaredLunde/essentials/issues
- npm.io page: https://npm.io/package/@essentials/memoize-one

## Recent versions

- 1.1.0 (latest) — 2020-06-05
- 1.0.4 — 2020-05-14
- 1.0.3 — 2020-04-10
- 1.0.2 — 2020-01-23
- 1.0.1 — 2019-11-25
- 1.0.0 — 2019-04-06

## README

<hr>
<div align="center">
  <h1 align="center">
    @essentials/memoize-one
  </h1>
</div>

<p align="center">
  <a href="https://bundlephobia.com/result?p=@essentials/memoize-one">
    <img alt="Bundlephobia" src="https://img.shields.io/bundlephobia/minzip/@essentials/memoize-one?style=for-the-badge&labelColor=24292e">
  </a>
  <a aria-label="Types" href="https://www.npmjs.com/package/@essentials/memoize-one">
    <img alt="Types" src="https://img.shields.io/npm/types/@essentials/memoize-one?style=for-the-badge&labelColor=24292e">
  </a>
  <a aria-label="NPM version" href="https://www.npmjs.com/package/@essentials/memoize-one">
    <img alt="NPM Version" src="https://img.shields.io/npm/v/@essentials/memoize-one?style=for-the-badge&labelColor=24292e">
  </a>
  <a aria-label="License" href="https://jaredlunde.mit-license.org/">
    <img alt="MIT License" src="https://img.shields.io/npm/l/@essentials/memoize-one?style=for-the-badge&labelColor=24292e">
  </a>
</p>

<pre align="center">npm i @essentials/memoize-one</pre>
<hr>

A memoization algorithm that only caches the result of the latest set of arguments, where argument equality is determined via a provided equality function.
The default `areEqual` function is a strict equality check on the first four arguments provided.

## Quick Start

```js
import memoOne from '@essentials/memoize-one'

const toUpper = memoOne(
  (value) => value.toUpperCase(),
  // are equal?
  (args, prevArgs) => args[0] === prevArgs[0]
)

toUpper('foo')
// FOO (uncached)
toUpper('foo')
// FOO (cached)
toUpper('foobar')
// FOOBAR (uncached)
toUpper('foo')
// FOO (uncached)
```

## API

### `memoOne(fn: Function, areEqual?: Function): any`

| Argument | Description                                                                     |
| -------- | ------------------------------------------------------------------------------- |
| fn       | The function you're memoizing the arguments and result of                       |
| areEqual | An equality function. Return `true` if the arguments are equal, `false` if not. |

## LICENSE

MIT

---
_Source: https://npm.io/package/@essentials/memoize-one · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
