From d3407b5a413c307237d54cc92788903f83cd5d3c Mon Sep 17 00:00:00 2001 From: Alex Friedman Date: Tue, 12 Apr 2016 08:52:08 -0400 Subject: [PATCH] Added definition files for koa-json (#8873) --- koa-json/koa-json-tests.ts | 15 ++++++++++++++ koa-json/koa-json.d.ts | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 koa-json/koa-json-tests.ts create mode 100644 koa-json/koa-json.d.ts diff --git a/koa-json/koa-json-tests.ts b/koa-json/koa-json-tests.ts new file mode 100644 index 000000000..d173aa83f --- /dev/null +++ b/koa-json/koa-json-tests.ts @@ -0,0 +1,15 @@ +/// +/// + +import * as Koa from "koa"; +import * as json from 'koa-json'; + +const app = new Koa(); + +app.use(json({ + pretty: false, + param: 'pretty', + spaces: 2 +})); + +app.listen(80) \ No newline at end of file diff --git a/koa-json/koa-json.d.ts b/koa-json/koa-json.d.ts new file mode 100644 index 000000000..24c87a810 --- /dev/null +++ b/koa-json/koa-json.d.ts @@ -0,0 +1,40 @@ +// Type definitions for koa-json v2.x +// Project: https://github.com/koajs/json +// Definitions by: Alex Friedman +// Definitions: https://github.com/brooklyndev/DefinitelyTyped + +/* =================== USAGE =================== + + import * as Koa from 'koa'; + import * as json from 'koa-json'; + + const app = new Koa(); + app.use(json()); + + =============================================== */ +/// + +declare module "koa-json" { + + import * as Koa from "koa"; + + function json(opts?:{ + + /** + * default to pretty response [true] + */ + pretty?: boolean, + + /** + * optional query-string param for pretty responses [none] + */ + param?: string, + + /** + * JSON spaces [2] + */ + spaces?: number + }) : { (ctx: Koa.Context, next?: () => any): any } ; + namespace json {} + export = json; +} \ No newline at end of file