add types for npmlog (#25291)

This commit is contained in:
Daniel Schmidt 2018-04-25 21:02:33 +02:00 committed by Wesley Wigham
parent 2d8ed8e3db
commit 41187d8875
4 changed files with 137 additions and 0 deletions

70
types/npmlog/index.d.ts vendored Normal file
View File

@ -0,0 +1,70 @@
// Type definitions for npmlog 4.1
// Project: https://github.com/npm/npmlog#readme
// Definitions by: Daniel Schmidt <https://github.com/DanielMSchmidt>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
export enum LogLevels {
silly = "silly",
verbose = "verbose",
info = "info",
http = "http",
warn = "warn",
error = "error",
}
export interface StyleObject {
fg?: string;
bg?: string;
bold?: boolean;
inverse?: boolean;
underline?: boolean;
bell?: boolean;
}
export interface MessageObject {
id: number;
level: string;
prefix: string;
message: string;
messageRaw: string;
}
// TODO: newStream, newGroup, setGaugeTemplate and setGaugeTemplateSet need to be added
interface npmlog {
log(level: LogLevels | string, prefix: string, message: string, ...args: any[]): void;
silly(prefix: string, message: string, ...args: any[]): void;
verbose(prefix: string, message: string, ...args: any[]): void;
info(prefix: string, message: string, ...args: any[]): void;
http(prefix: string, message: string, ...args: any[]): void;
warn(prefix: string, message: string, ...args: any[]): void;
error(prefix: string, message: string, ...args: any[]): void;
level: string;
record: MessageObject[];
maxRecordSize: number;
prefixStyle: StyleObject;
headingStyle: StyleObject;
heading: string;
stream: any; // Defaults to process.stderr
enableColor(): void;
disableColor(): void;
enableProgress(): void;
disableProgress(): void;
enableUnicode(): void;
disableUnicode(): void;
pause(): void;
resume(): void;
addLevel(level: string, n: number, style?: StyleObject, disp?: string): void;
}
declare const logger: npmlog;
export default logger;

View File

@ -0,0 +1,43 @@
import npmlog from "npmlog";
const prefix = "str";
const message = "otherStr";
['silly', 'verbose', 'info', 'http', 'warn', 'error'].forEach(lvl => npmlog.log(lvl, prefix, message));
npmlog.silly(prefix, message);
npmlog.verbose(prefix, message);
npmlog.info(prefix, message);
npmlog.http(prefix, message);
npmlog.warn(prefix, message);
npmlog.error(prefix, message);
npmlog.level = "silly";
npmlog.enableColor();
npmlog.disableColor();
npmlog.enableProgress();
npmlog.disableProgress();
npmlog.enableUnicode();
npmlog.disableUnicode();
npmlog.pause();
npmlog.resume();
npmlog.addLevel("new-level", 42);
npmlog.addLevel("styled-level", 42, {
fg: 'red',
bg: 'blue',
bold: false,
inverse: true,
underline: true,
bell: false
});
npmlog.addLevel("styled-level", 42, {
fg: 'red',
bold: false,
underline: true,
}, 'display name');

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",
"npmlog-tests.ts"
]
}

1
types/npmlog/tslint.json Normal file
View File

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