Socket
Socket
Sign inDemoInstall

memoize-id

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

memoize-id

Memoize a function by the identity of its arguments, using ES2015 Map


Version published
Maintainers
1
Weekly downloads
188
increased by9.94%
Install size
23.9 kB

Weekly downloads

Readme

Source

memoize-id npm

Memoize a function by the identity of its arguments, using ES2015 Map.

Installation

npm install memoize-id

Note: ES2015 Symbol and Map must be available where memoize-id is used. Refer to ECMAScript 6 compatibility table.

Usage

import memoize from 'memoize-id';
// or:
// const memoize = require('memoize-id').default;

let i = 0;
function fn(foo, bar, baz) {
  i += 1;
  return {
    args: [foo, bar, baz],
    i,
  };
}
const memoizedFn = memoize(fn);

console.log(i);
// 0
const v1 = memoizedFn('foo', 'bar', 'baz');
console.log(v1);
// { args: ['foo', 'bar', 'baz'], i: 1 }
console.log(i);
// 1
const v2 = memoizedFn('foo', 'bar', 'baz');
console.log(v2);
// { args: ['foo', 'bar', 'baz'], i: 1 }
console.log(v1 === v2);
// true
console.log(i);
// 1
const v3 = memoizedFn('foo', 'qux', 'baz');
console.log(v3);
// { args: ['foo', 'qux', 'baz'], i: 2 }
console.log(i);
// 2
console.log(v1 == v3);
// false

Keywords

FAQs

Last updated on 02 May 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc