forked from sindresorhus/clear-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
65 lines (47 loc) · 1.35 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
interface Options {
/**
Optional filter function. function should return false to prevent the module from being removed from cache.
Use case: To prevent any module in node_modules from being uncached.
`clearModule('./my-module', { filter: name => !name.match(/node_modules/) })`
@default undefined
*/
readonly filter?: (fullPath: string) => boolean
}
declare const clear: {
/**
Clear a module from the [cache](https://nodejs.org/api/modules.html#modules_caching).
@param moduleId - What you would use with `require()`.
@example
```
// foo.ts
let i = 0;
module.exports = () => ++i;
// test.ts
import clearModule = require('clear-module');
require('./foo')();
//=> 1
require('./foo')();
//=> 2
clearModule('./foo');
require('./foo')();
//=> 1
```
*/
(moduleId: string, options?: Options): void;
/**
Clear all modules from the cache.
*/
all(): void;
/**
Clear all matching modules from the cache.
@param regex - Regex to match against the module IDs.
*/
match(regex: RegExp): void;
/**
Clear a single module from the cache non-recursively. No parent or children modules will be affected.
This is mostly only useful if you use singletons, where you would want to clear a specific module without causing any side effects.
@param moduleId - What you would use with `require()`.
*/
single(moduleId: string): void;
};
export = clear;