You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@pacote/memoize

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pacote/memoize

Memoization function.

2.0.1
npmnpm
Version published
Weekly downloads
460
-20.42%
Maintainers
1
Weekly downloads
 
Created
Source

@pacote/memoize

version minified minified + gzip

Speed up consecutive calls of the same function with the same arguments by caching its results.

Installation

yarn add @pacote/memoize

Usage

import { memoize } from '@pacote/memoize'

const randomFunction = (prefix: string) => `${prefix}${Math.random()}`

const memoizedFunction = memoize((prefix) => `key_${prefix}`, randomFunction)

memoizedFunction('foo') // 'foo' followed by randomly-generated number.
memoizedFunction('foo') // Same result as previous call with 'foo'.

memoizedFunction('bar') // 'bar' followed by randomly-generated number.
memoizedFunction('bar') // Same result as previous call with 'bar'.

memoize<A, T>(cacheKeyFn: (...args: A) => string, fn: (...args: A) => T): (...args: A) => T

memoize() takes two function arguments:

  • A function that generates a string key for cached results. This function takes the same arguments as the function to memoize.

  • The function to memoize. memoize() returns a version of this function that caches results.

License

MIT © Luís Rodrigues.

Keywords

memoize

FAQs

Package last updated on 22 Apr 2023

Did you know?

Socket

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