mem-map

1.0.1 • Public • Published

mem-map Build Status

Map to be used with mem

Please note that this is not a ponyfill for Map. Although it will use the native Map implementation if available. If Map is not available, a very lightweight Map is offerred which only implements get, set and has. This is just enough so it can be used with mem if you want to support older Node versions.

Install

$ npm install --save mem-map

Usage

const Map = require('mem-map');
const mem = require('mem');

let i = 0;
const counter = () => ++i;

const memoized = mem(counter, {cache: new Map()});

memoized('foo');
//=> 1

// cached as it's the same arguments
memoized('foo');
//=> 1

// not cached anymore as the arguments changed
memoized('bar');
//=> 2

memoized('bar');
//=> 2

License

MIT © Sam Verschueren

Package Sidebar

Install

npm i mem-map

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • samverschueren