just-memoize
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

just-memoize

Part of a library of zero-dependency npm modules that do just do one thing. Guilt-free utilities for every occasion.

🍦 Try it

npm install just-memoize
yarn add just-memoize

An implementation of the memoize technique

import memoize from 'just-memoize';

const sumByOne = memoize(function(value) {
  return value + 1;
});

sumByOne(10); // Returns value returned by the function
sumByOne(10); // Cache hit!

sumByOne(20); // Returns value returned by the function
sumByOne(20); // Cache hit!

// Custom cache key (key defaults to JSON stringified arguments)
var sum = memoize(function(a, b) {
  return a + b;
}, function(a, b) {
  return `${a}-${b}`;
});

sum(10, 10); // Returns value returned by the function
sum(10, 20); // Returns value returned by the function
sum(10, 20); // Cache hit!

Readme

Keywords

Package Sidebar

Install

npm i just-memoize

Weekly Downloads

7,743

Version

2.2.0

License

MIT

Unpacked Size

6.15 kB

Total Files

9

Last publish

Collaborators

  • angus-c