UNPKG

2.08 kBTypeScriptView Raw
1/* =================== USAGE ===================
2
3 import bodyParser = require("koa-bodyparser");
4 var Koa = require('koa');
5
6 var app = new Koa();
7 app.use(bodyParser());
8
9 =============================================== */
10
11import * as Koa from "koa";
12
13declare module "koa" {
14 interface Request {
15 body?: unknown;
16 rawBody: string;
17 }
18}
19
20declare function bodyParser(opts?: bodyParser.Options): Koa.Middleware;
21
22declare namespace bodyParser {
23 interface Options {
24 /**
25 * parser will only parse when request type hits enableTypes, default is ['json', 'form'].
26 */
27 enableTypes?: string[] | undefined;
28
29 /**
30 * requested encoding. Default is utf-8 by co-body
31 */
32 encoding?: string | undefined;
33
34 /**
35 * limit of the urlencoded body. If the body ends up being larger than this limit
36 * a 413 error code is returned. Default is 56kb
37 */
38 formLimit?: string | undefined;
39
40 /**
41 * limit of the json body. Default is 1mb
42 */
43 jsonLimit?: string | undefined;
44
45 /**
46 * limit of the text body. Default is 1mb.
47 */
48 textLimit?: string | undefined;
49
50 /**
51 * limit of the xml body. Default is 1mb.
52 */
53 xmlLimit?: string | undefined;
54
55 /**
56 * when set to true, JSON parser will only accept arrays and objects. Default is true
57 */
58 strict?: boolean | undefined;
59
60 /**
61 * custom json request detect function. Default is null
62 */
63 detectJSON?: ((ctx: Koa.Context) => boolean) | undefined;
64
65 /**
66 * support extend types
67 */
68 extendTypes?: {
69 json?: string[] | string | undefined;
70 form?: string[] | string | undefined;
71 text?: string[] | string | undefined;
72 } | undefined;
73
74 /**
75 * support custom error handle
76 */
77 onerror?: ((err: Error, ctx: Koa.Context) => void) | undefined;
78 }
79}
80
81export = bodyParser;
82
\No newline at end of file