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

mem

Package Overview
Dependencies
Maintainers
2
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 7.0.0-3 to 8.0.0

22

dist/index.d.ts

@@ -0,9 +1,14 @@

declare type AnyFunction = (...arguments_: any) => any;
interface CacheStorageContent<ValueType> {
data: ValueType;
maxAge: number;
}
interface CacheStorage<KeyType, ValueType> {
has: (key: KeyType) => boolean;
get: (key: KeyType) => ValueType | undefined;
set: (key: KeyType, value: ValueType) => void;
get: (key: KeyType) => CacheStorageContent<ValueType> | undefined;
set: (key: KeyType, value: CacheStorageContent<ValueType>) => void;
delete: (key: KeyType) => void;
clear?: () => void;
}
interface Options<ArgumentsType extends unknown[], CacheKeyType, ReturnType> {
interface Options<FunctionToMemoize extends AnyFunction, CacheKeyType> {
/**

@@ -40,3 +45,3 @@ Milliseconds until the cache expires.

*/
readonly cacheKey?: (arguments_: ArgumentsType) => CacheKeyType;
readonly cacheKey?: (arguments_: Parameters<FunctionToMemoize>) => CacheKeyType;
/**

@@ -48,6 +53,3 @@ Use a different cache storage. Must implement the following methods: `.has(key)`, `.get(key)`, `.set(key, value)`, `.delete(key)`, and optionally `.clear()`. You could for example use a `WeakMap` instead or [`quick-lru`](https://github.com/sindresorhus/quick-lru) for a LRU cache.

*/
readonly cache?: CacheStorage<CacheKeyType, {
data: ReturnType;
maxAge: number;
}>;
readonly cache?: CacheStorage<CacheKeyType, ReturnType<FunctionToMemoize>>;
}

@@ -83,3 +85,3 @@ /**

declare const mem: {
<ArgumentsType extends any[], ReturnType_1 extends unknown, CacheKeyType, FunctionToMemoize extends (...arguments_: ArgumentsType) => ReturnType_1>(fn: FunctionToMemoize, { cacheKey, cache, maxAge }?: Options<ArgumentsType, CacheKeyType, ReturnType_1>): FunctionToMemoize;
<FunctionToMemoize extends AnyFunction, CacheKeyType>(fn: FunctionToMemoize, { cacheKey, cache, maxAge }?: Options<FunctionToMemoize, CacheKeyType>): FunctionToMemoize;
/**

@@ -90,4 +92,4 @@ Clear all cached data of a memoized function.

*/
clear(fn: (...arguments_: any[]) => any): void;
clear(fn: AnyFunction): void;
};
export = mem;

@@ -35,3 +35,3 @@ 'use strict';

if (typeof maxAge === 'number') {
// TODO: drop after https://github.com/SamVerschueren/map-age-cleaner/issues/5
// TODO: Drop after https://github.com/SamVerschueren/map-age-cleaner/issues/5
// @ts-expect-error

@@ -68,10 +68,11 @@ mapAgeCleaner(cache);

mem.clear = (fn) => {
if (!cacheStore.has(fn)) {
throw new Error('Can\'t clear a function that was not memoized!');
}
const cache = cacheStore.get(fn);
if (typeof cache.clear === 'function') {
cache.clear();
if (!cache) {
throw new TypeError('Can\'t clear a function that was not memoized!');
}
if (typeof cache.clear !== 'function') {
throw new TypeError('The cache Map can\'t be cleared!');
}
cache.clear();
};
module.exports = mem;
{
"name": "mem",
"version": "7.0.0-3",
"version": "8.0.0",
"description": "Memoize functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input",

@@ -42,9 +42,11 @@ "license": "MIT",

"map-age-cleaner": "^0.1.3",
"mimic-fn": "^3.0.0"
"mimic-fn": "^3.1.0"
},
"devDependencies": {
"@ava/typescript": "^1.1.1",
"@sindresorhus/tsconfig": "^0.7.0",
"@types/serialize-javascript": "^4.0.0",
"ava": "^3.13.0",
"del-cli": "^3.0.1",
"delay": "^4.1.0",
"delay": "^4.4.0",
"serialize-javascript": "^5.0.1",

@@ -54,3 +56,21 @@ "tsd": "^0.13.1",

"xo": "^0.33.1"
},
"ava": {
"files": [
"test.ts"
],
"timeout": "1m",
"typescript": {
"rewritePaths": {
"./": "dist/"
}
}
},
"xo": {
"rules": {
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-function": "off"
}
}
}

@@ -1,2 +0,2 @@

# mem [![Build Status](https://travis-ci.org/sindresorhus/mem.svg?branch=master)](https://travis-ci.org/sindresorhus/mem)
# mem [![Build Status](https://travis-ci.com/sindresorhus/mem.svg?branch=master)](https://travis-ci.com/github/sindresorhus/mem)

@@ -3,0 +3,0 @@ > [Memoize](https://en.wikipedia.org/wiki/Memoization) functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input

Sorry, the diff of this file is not supported yet

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