Giter Site home page Giter Site logo

sindresorhus / filter-console Goto Github PK

View Code? Open in Web Editor NEW
243.0 4.0 9.0 9 KB

Filter out unwanted `console.log()` output

License: MIT License

JavaScript 89.16% TypeScript 10.84%
console-log console devtools filter exclude nodejs browser npm-package

filter-console's Introduction

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

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.

filter-console's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

filter-console's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.