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


Version published
Weekly downloads
111
decreased by-41.27%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

memoize-id [![npm][npm-badge]][npm] [![Build Status][travis-badge]][travis]

Memoize a function by the identity of its arguments, using [ES2015 Map][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

[Map]: (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map [Symbol]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Symbol [npm]: https://www.npmjs.com/package/memoize-id [npm-badge]: https://img.shields.io/npm/v/memoize-id.svg [travis]: https://travis-ci.org/elliottsj/memoize-id [travis-badge]: https://travis-ci.org/elliottsj/memoize-id.svg?branch=master

Keywords

FAQs

Last updated on 20 Feb 2016

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