New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

tiny-mem

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-mem

Minimal, no-dependencies memoization helper

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

tiny-mem

Minimal, no-dependencies memoization helper.

Motivation

Lodash has a handy memoize function but it also has a ton of other functions. Sindre Sorhus' mem is great but is also full of features you may not need.

This package is a simple, memoizing function implementation that does just that. No fancy options, just like an MVP.

Install

npm install tiny-mem

Usage

const memoize = require('tiny-mem')

let index = 0
const seq = () => ++index
const memoized = memoize(seq)

memoized('one') // Returns 1

memoized('two') // Returns 2
memoized('two') // Returns 2 again

memoized('one') // Returns 1 again

memoized('two', 'one') // Still returns 2

API

memoize(fn, options?)

Returns a memoized function.

fn

Type: Function

A function.

options?

Type: object

options.cache?

Type: object Default: new Map()

The cache storage. Must implement these methods: has(key), set(key, value), get(key) and delete(key)

options.resolver?

Type: Function Default: (...args) => args[0]

Determines how the caching key will be computed. By default, it will only consider the first argument and use strict equality to evaluate a match.

memoizedFn

The memoized version of fn. It resolves to the result of calling fn(), which is called only once per key.

Keywords

cache

FAQs

Package last updated on 29 Jun 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