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