From e0f099ceb4832670df7cb31305d80aaa87f7ad5b Mon Sep 17 00:00:00 2001 From: hellopao Date: Thu, 7 Apr 2016 10:25:53 +0800 Subject: [PATCH] add difinitions for koa-compress --- koa-compress/koa-compress-tests.ts | 16 ++++++++++++ koa-compress/koa-compress.d.ts | 41 ++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 koa-compress/koa-compress-tests.ts create mode 100644 koa-compress/koa-compress.d.ts diff --git a/koa-compress/koa-compress-tests.ts b/koa-compress/koa-compress-tests.ts new file mode 100644 index 0000000000..564fd53e2c --- /dev/null +++ b/koa-compress/koa-compress-tests.ts @@ -0,0 +1,16 @@ +/// +/// + +import * as Koa from "koa"; +import compress = require("koa-compress"); + +const app = new Koa(); + +app.use(compress({ + filter: (ctype) => { + return /text/i.test(ctype) + }, + threshold: 2048 +})); + +app.listen(80) \ No newline at end of file diff --git a/koa-compress/koa-compress.d.ts b/koa-compress/koa-compress.d.ts new file mode 100644 index 0000000000..3a6b7e09e1 --- /dev/null +++ b/koa-compress/koa-compress.d.ts @@ -0,0 +1,41 @@ +// Type definitions for koa-compress v2.x +// Project: https://github.com/koajs/compress +// Definitions by: Jerry Chin +// Definitions: https://github.com/hellopao/DefinitelyTyped + +/* =================== USAGE =================== + + import compress = require("koa-compress"); + var Koa = require('koa'); + + var app = new Koa(); + app.use(compress()); + + =============================================== */ +/// +/// + +declare module "koa-compress" { + + import * as Koa from "koa"; + import * as zlib from "zlib"; + + interface ICompressOptions extends zlib.ZlibOptions { + /** + * An optional function that checks the response content type to decide whether to compress. By default, it uses compressible. + */ + filter?: (content_type: string) => boolean; + + /** + * Minimum response size in bytes to compress. Default 1024 bytes or 1kb. + */ + threshold?: number + } + + /** + * Compress middleware for Koa + */ + function compress(options?: ICompressOptions): { (ctx: Koa.Context, next?: () => any): any }; + + export = compress; +}