-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.d.ts
69 lines (53 loc) · 1.55 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
66
67
68
69
type ConsoleMethods = 'log' | 'debug' | 'info' | 'warn' | 'error';
export type Console = Record<
ConsoleMethods,
(message?: unknown, ...optionalParameters: unknown[]) => void
>;
export interface Options {
/**
Console methods to filter.
@default ['log', 'debug', 'info', 'warn', 'error']
*/
readonly methods?: readonly ConsoleMethods[];
/**
Use a custom `console` object. Can be useful for testing or mocking.
@default console
*/
readonly console?: Console;
}
/**
Filter out unwanted `console.log()` output.
Can be useful when you don't control the output, for example, filtering out PropType warnings from a third-party React component.
@param excludePatterns - Console output that matches any of the given patterns are filtered from being logged.
Filter types:
- `string`: Checks if the string pattern is included in the console output.
- `RegExp`: Checks if the RegExp pattern matches the console output.
- `Function`: Receives the console output as a string and is expected to return a truthy/falsy value of whether to exclude it.
@returns A function, which when called, disables the filter.
@example
```
import filterConsole from 'filter-console';
const disableFilter = filterConsole(['🐼']);
const log = () => {
console.log('');
console.log('🦄');
console.log('🐼');
console.log('🐶');
};
log();
disableFilter();
log();
// $ node example.js
//
// 🦄
// 🐶
//
// 🦄
// 🐼
// 🐶
```
*/
export default function filterConsole(
excludePatterns: Array<string | RegExp | ((output: string) => boolean)>,
options?: Options
): () => void;