Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/filter-console
Filter out unwanted `console.log()` output
https://github.com/sindresorhus/filter-console
browser console console-log devtools exclude filter nodejs npm-package
Last synced: about 1 month ago
JSON representation
Filter out unwanted `console.log()` output
- Host: GitHub
- URL: https://github.com/sindresorhus/filter-console
- Owner: sindresorhus
- License: mit
- Created: 2018-10-10T08:03:36.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2022-07-08T11:26:58.000Z (over 2 years ago)
- Last Synced: 2024-04-13T16:33:34.697Z (7 months ago)
- Topics: browser, console, console-log, devtools, exclude, filter, nodejs, npm-package
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 243
- Watchers: 4
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- awesome-list - filter-console
README
# filter-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.
## Install
```
$ npm install filter-console
```## Usage
```js
import filterConsole from 'filter-console';const disableFilter = filterConsole(['🐼']);
const log = () => {
console.log('');
console.log('🦄');
console.log('🐼');
console.log('🐶');
};log();
disableFilter();
log();
``````
$ node example.js🦄
🐶🦄
🐼
🐶
```## API
### filterConsole(excludePatterns, options?)
Returns a function, which when called, disables the filter.
#### excludePatterns
Type: `Array`
Console output that matches any of the given patterns are filtered from being logged. The patterns are matched against what would be logged and not the `console` method input arguments directly. Meaning an exclude pattern of `'foo bar'` will match `console.log('foo %s', 'bar')`.
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.#### options
Type: `object`
##### methods
Type: `string[]`\
Default: `['log', 'debug', 'info', 'warn', 'error']`Console methods to filter.
##### console
Type: `object`\
Default: `console`Use a custom `console` object. Can be useful for testing or mocking.