Add type definitions for "koa-log" package

This commit is contained in:
Uladzimir Havenchyk
2018-12-04 10:53:55 +03:00
parent 24077f2cd0
commit 36367f80e8
4 changed files with 67 additions and 0 deletions

33
types/koa-log/index.d.ts vendored Normal file
View File

@@ -0,0 +1,33 @@
// Type definitions for koa-log 2.1
// Project: https://github.com/vicanso/koa-log#readme
// Definitions by: Uladzimir Havenchyk <https://github.com/havenchyk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as Koa from 'koa';
declare function koaLog(type: string): Koa.Middleware;
declare namespace koaLog {
namespace morgan {
function cookie(ctx: Koa.BaseContext, key: string): string;
function date(ctx: Koa.BaseContext, format: string): string;
function format(name: string): string;
function length(ctx: Koa.BaseContext): number | undefined;
function method(ctx: Koa.BaseContext): string;
function referrer(ctx: Koa.BaseContext): string;
function status(ctx: Koa.BaseContext): number;
function token(name: string, fn: (ctx: Koa.BaseContext) => string): void;
function url(ctx: Koa.BaseContext): string;
}
}
export = koaLog;

View File

@@ -0,0 +1,10 @@
import Koa = require('koa');
import koaLogger = require('koa-log');
koaLogger.morgan.token('request-body', (ctx: Koa.BaseContext) => JSON.stringify(ctx.request.body));
koaLogger.morgan.token('response-body', (ctx: Koa.BaseContext) => JSON.stringify(ctx.body));
const app = new Koa();
app.use(
koaLogger(':status :method :url took :response-time ms :request-body :response-body')
);

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

View File

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