mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-04-14 09:34:39 +00:00
logform: Provides its own types (#39456)
This commit is contained in:
committed by
Jesse Trinity
parent
4b22063e77
commit
9a499c93e8
@@ -2034,6 +2034,12 @@
|
||||
"sourceRepoURL": "https://github.com/nomiddlename/log4js-node",
|
||||
"asOfVersion": "2.3.5"
|
||||
},
|
||||
{
|
||||
"libraryName": "logform",
|
||||
"typingsPackageName": "logform",
|
||||
"sourceRepoURL": "https://github.com/winstonjs/logform",
|
||||
"asOfVersion": "1.10.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "loglevel",
|
||||
"typingsPackageName": "loglevel",
|
||||
|
||||
51
types/logform/index.d.ts
vendored
51
types/logform/index.d.ts
vendored
@@ -1,51 +0,0 @@
|
||||
// Type definitions for logform 1.2
|
||||
// Project: https://github.com/winstonjs/logform
|
||||
// Definitions by: DABH <https://github.com/DABH>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
export interface TransformableInfo {
|
||||
level: string;
|
||||
message: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export type TransformFunction = (info: TransformableInfo, opts?: any) => TransformableInfo | boolean;
|
||||
export type Colors = { [key: string]: string | string[] }; // tslint:disable-line interface-over-type-literal
|
||||
export type FormatWrap = (opts?: any) => Format;
|
||||
|
||||
export class Format {
|
||||
constructor(opts?: object);
|
||||
|
||||
options?: object;
|
||||
transform: TransformFunction;
|
||||
}
|
||||
|
||||
export class Colorizer extends Format {
|
||||
constructor(opts?: object);
|
||||
|
||||
createColorize: (opts?: object) => Colorizer;
|
||||
addColors: (colors: Colors) => Colors;
|
||||
colorize: (level: string, message: string) => string;
|
||||
}
|
||||
|
||||
export function format(transform: TransformFunction): FormatWrap;
|
||||
|
||||
export function levels(config: object): object;
|
||||
|
||||
export namespace format {
|
||||
function align(opts?: object): Format;
|
||||
function cli(opts?: object): Format;
|
||||
function colorize(opts?: object): Colorizer;
|
||||
function combine(...formats: Format[]): Format;
|
||||
function json(opts?: object): Format;
|
||||
function label(opts?: object): Format;
|
||||
function logstash(opts?: object): Format;
|
||||
function padLevels(opts?: object): Format;
|
||||
function prettyPrint(opts?: object): Format;
|
||||
function printf(templateFunction: (info: TransformableInfo) => string): Format;
|
||||
function simple(opts?: object): Format;
|
||||
function splat(opts?: object): Format;
|
||||
function timestamp(opts?: object): Format;
|
||||
function uncolorize(opts?: object): Format;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
import * as logform from 'logform';
|
||||
const format = logform.format;
|
||||
const { combine, timestamp, label } = format;
|
||||
|
||||
const labelTimestamp = combine(
|
||||
label({ label: 'right meow!' }),
|
||||
timestamp()
|
||||
);
|
||||
|
||||
const info = labelTimestamp.transform({
|
||||
level: 'info',
|
||||
message: 'What time is the testing at?'
|
||||
});
|
||||
|
||||
const ignorePrivate = format((info, opts) => {
|
||||
if (info.private) { return false; }
|
||||
return info;
|
||||
})();
|
||||
|
||||
ignorePrivate.transform({
|
||||
level: 'error',
|
||||
message: 'Public error to share'
|
||||
});
|
||||
|
||||
ignorePrivate.transform({
|
||||
level: 'error',
|
||||
private: true,
|
||||
message: 'This is super secret - hide it.'
|
||||
});
|
||||
|
||||
const willNeverThrow = format.combine(
|
||||
format(info => false)(), // Ignores everything
|
||||
format(info => { throw new Error('Never reached'); })()
|
||||
);
|
||||
|
||||
const volume = format((info, opts) => {
|
||||
if (opts && opts.yell) {
|
||||
info.message = info.message.toUpperCase();
|
||||
} else if (opts && opts.whisper) {
|
||||
info.message = info.message.toLowerCase();
|
||||
}
|
||||
|
||||
return info;
|
||||
});
|
||||
|
||||
// `volume` is now a function that returns instances of the format.
|
||||
const scream = volume({ yell: true });
|
||||
scream.transform({
|
||||
level: 'info',
|
||||
message: `sorry for making you YELL in your head!`
|
||||
}, scream.options);
|
||||
|
||||
// `volume` can be used multiple times to create different formats.
|
||||
const whisper = volume({ whisper: true });
|
||||
whisper.transform({
|
||||
level: 'info',
|
||||
message: `WHY ARE THEY MAKING US YELL SO MUCH!`
|
||||
}, whisper.options);
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"logform-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user