[filter-console] Add types

This commit is contained in:
Dimitri Benin
2019-01-17 23:57:13 +01:00
parent 272bcf47b2
commit 89b42315f3
4 changed files with 76 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
import filterConsole = require('filter-console');
const disableFilter = filterConsole(['🐼']);
disableFilter; // $ExpectType () => void
filterConsole([/🐼/]);
filterConsole([input => input === '🐼']);
disableFilter();

44
types/filter-console/index.d.ts vendored Normal file
View File

@@ -0,0 +1,44 @@
// Type definitions for filter-console 0.1
// Project: https://github.com/sindresorhus/filter-console#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
/// <reference types="node" />
export = filterConsole;
/**
* 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.
* 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')`.
* @returns A function, which when called, disables the filter.
*/
declare function filterConsole(
excludePatterns: Array<string | RegExp | ((output: string) => boolean)>,
options?: filterConsole.Options
): () => void;
declare namespace filterConsole {
interface Options {
/**
* Console methods to filter.
* @default ['log', 'debug', 'info', 'warn', 'error']
*/
methods?: Array<'log' | 'debug' | 'info' | 'warn' | 'error'>;
/**
* Use a custom `console` object. Can be useful for testing or mocking.
*/
console?: Console;
}
type Console = Record<
'log' | 'debug' | 'info' | 'warn' | 'error',
(message?: any, ...optionalParams: any[]) => void
>;
}

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"filter-console-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }