# filter-console

> Filter out unwanted `console.log()` output

Latest version **1.0.0** (published 2021-08-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install filter-console
pnpm add filter-console
yarn add filter-console
bun add filter-console
```

## Health

**Score 38/100 (D)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-08-26 |
| First published | 2018-10-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/filter-console) |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 244 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | filter, console, console-log, log, logging, exclude, exclusion, devtools, pattern, patterns, test, testing, mock, electron, react, proptypes |

## Links

- npm: https://www.npmjs.com/package/filter-console
- Repository: https://github.com/sindresorhus/filter-console
- Homepage: https://github.com/sindresorhus/filter-console#readme
- Issues: https://github.com/sindresorhus/filter-console/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/filter-console

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2021-08-26
- 0.1.1 — 2019-04-15
- 0.1.0 — 2018-10-10

## 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<string | RegExp | Function>`

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.

---
_Source: https://npm.io/package/filter-console · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
