Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mem

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mem - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

16

index.js
'use strict';
const mimicFn = require('mimic-fn');
const cacheStore = new WeakMap();
const defaultCacheKey = function (x) {

@@ -19,3 +21,3 @@ if (arguments.length === 1 && (x === null || x === undefined || (typeof x !== 'function' && typeof x !== 'object'))) {

const memoized = function () {
const cache = memoized.__cache__;
const cache = cacheStore.get(memoized);
const key = opts.cacheKey.apply(null, arguments);

@@ -41,7 +43,15 @@

memoized.__cache__ = opts.cache;
mimicFn(memoized, fn);
cacheStore.set(memoized, opts.cache);
return memoized;
};
module.exports.clear = fn => {
const cache = cacheStore.get(fn);
if (cache && typeof cache.clear === 'function') {
cache.clear();
}
};

2

package.json
{
"name": "mem",
"version": "1.0.0",
"version": "1.1.0",
"description": "Memoize functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -77,5 +77,5 @@ # mem [![Build Status](https://travis-ci.org/sindresorhus/mem.svg?branch=master)](https://travis-ci.org/sindresorhus/mem)

### mem(input, [options])
### mem(fn, [options])
#### input
#### fn

@@ -105,8 +105,18 @@ Type: `Function`

Type: `Object`
Type: `Object`<br>
Default: `new Map()`
Use a different cache storage. Must implement the following methods: `.has(key)`, `.get(key)`, `.set(key, value)`. You could for example use a `WeakMap` instead.
Use a different cache storage. Must implement the following methods: `.has(key)`, `.get(key)`, `.set(key, value)`, and optionally `.clear()`. You could for example use a `WeakMap` instead.
### mem.clear(fn)
Clear all cached data of a memoized function.
#### fn
Type: `Function`
Memoized function.
## Tips

@@ -113,0 +123,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc