@essentials/memoize-one
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@essentials/memoize-one

Bundlephobia Types NPM Version MIT License

npm i @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. The default areEqual function is a strict equality check on the first four arguments provided.

Quick Start

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

Dependencies (0)

    Dev Dependencies (11)

    Package Sidebar

    Install

    npm i @essentials/memoize-one

    Weekly Downloads

    12,815

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    12.4 kB

    Total Files

    20

    Last publish

    Collaborators

    • jaredlunde