Fix dependabot issues
This commit is contained in:
parent
c89d9bd8b0
commit
531c6ba7c8
705 changed files with 53406 additions and 20466 deletions
62
node_modules/mem/readme.md
generated
vendored
62
node_modules/mem/readme.md
generated
vendored
|
|
@ -1,4 +1,4 @@
|
|||
# mem [](https://travis-ci.org/sindresorhus/mem)
|
||||
# mem
|
||||
|
||||
> [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
|
||||
|
||||
|
|
@ -6,14 +6,12 @@ Memory is automatically released when an item expires or the cache is cleared.
|
|||
|
||||
By default, **only the first argument is considered** and it only works with [primitives](https://developer.mozilla.org/en-US/docs/Glossary/Primitive). If you need to cache multiple arguments or cache `object`s *by value*, have a look at alternative [caching strategies](#caching-strategy) below.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install mem
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
|
|
@ -69,15 +67,15 @@ const delay = require('delay');
|
|||
const memGot = mem(got, {maxAge: 1000});
|
||||
|
||||
(async () => {
|
||||
await memGot('sindresorhus.com');
|
||||
await memGot('https://sindresorhus.com');
|
||||
|
||||
// This call is cached
|
||||
await memGot('sindresorhus.com');
|
||||
await memGot('https://sindresorhus.com');
|
||||
|
||||
await delay(2000);
|
||||
|
||||
// This call is not cached as the cache has expired
|
||||
await memGot('sindresorhus.com');
|
||||
await memGot('https://sindresorhus.com');
|
||||
})();
|
||||
```
|
||||
|
||||
|
|
@ -156,7 +154,6 @@ addOneListener(mainContent, 'load', console.log); // `addListener` is run, and i
|
|||
|
||||
Better yet, if your function’s arguments are compatible with `WeakMap`, you should use [`deep-weak-map`](https://github.com/futpib/deep-weak-map) instead of `many-keys-map`. This will help avoid memory leaks.
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### mem(fn, options?)
|
||||
|
|
@ -193,12 +190,50 @@ Refer to the [caching strategies](#caching-strategy) section for more informatio
|
|||
##### cache
|
||||
|
||||
Type: `object`\
|
||||
Default: `new Map()`, but it also intelligently uses `new WeakMap()` whenevever possible
|
||||
Default: `new Map()`
|
||||
|
||||
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 [`quick-lru`](https://github.com/sindresorhus/quick-lru) for a LRU cache.
|
||||
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.
|
||||
|
||||
Refer to the [caching strategies](#caching-strategy) section for more information.
|
||||
|
||||
### mem.decorator(options)
|
||||
|
||||
Returns a [decorator](https://github.com/tc39/proposal-decorators) to memoize class methods or static class methods.
|
||||
|
||||
Notes:
|
||||
|
||||
- Only class methods and getters/setters can be memoized, not regular functions (they aren't part of the proposal);
|
||||
- Only [TypeScript’s decorators](https://www.typescriptlang.org/docs/handbook/decorators.html#parameter-decorators) are supported, not [Babel’s](https://babeljs.io/docs/en/babel-plugin-proposal-decorators), which use a different version of the proposal;
|
||||
- Being an experimental feature, they need to be enabled with `--experimentalDecorators`; follow TypeScript’s docs.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
Same as options for `mem()`.
|
||||
|
||||
```ts
|
||||
import mem = require('mem');
|
||||
|
||||
class Example {
|
||||
index = 0
|
||||
|
||||
@mem.decorator()
|
||||
counter() {
|
||||
return ++this.index;
|
||||
}
|
||||
}
|
||||
|
||||
class ExampleWithOptions {
|
||||
index = 0
|
||||
|
||||
@mem.decorator({maxAge: 1000})
|
||||
counter() {
|
||||
return ++this.index;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### mem.clear(fn)
|
||||
|
||||
Clear all cached data of a memoized function.
|
||||
|
|
@ -209,7 +244,6 @@ Type: `Function`
|
|||
|
||||
Memoized function.
|
||||
|
||||
|
||||
## Tips
|
||||
|
||||
### Cache statistics
|
||||
|
|
@ -227,21 +261,19 @@ const cache = new StatsMap();
|
|||
const memGot = mem(got, {cache});
|
||||
|
||||
(async () => {
|
||||
await memGot('sindresorhus.com');
|
||||
await memGot('sindresorhus.com');
|
||||
await memGot('sindresorhus.com');
|
||||
await memGot('https://sindresorhus.com');
|
||||
await memGot('https://sindresorhus.com');
|
||||
await memGot('https://sindresorhus.com');
|
||||
|
||||
console.log(cache.stats);
|
||||
//=> {hits: 2, misses: 1}
|
||||
})();
|
||||
```
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [p-memoize](https://github.com/sindresorhus/p-memoize) - Memoize promise-returning & async functions
|
||||
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue