UNPKG

3.84 kBTypeScriptView Raw
1/// <reference types="node" />
2
3import { NextHandleFunction } from "connect";
4import * as http from "http";
5
6// for docs go to https://github.com/expressjs/body-parser/tree/1.19.0#body-parser
7
8declare namespace bodyParser {
9 interface BodyParser {
10 /**
11 * @deprecated use individual json/urlencoded middlewares
12 */
13 (options?: OptionsJson & OptionsText & OptionsUrlencoded): NextHandleFunction;
14 /**
15 * Returns middleware that only parses json and only looks at requests
16 * where the Content-Type header matches the type option.
17 */
18 json(options?: OptionsJson): NextHandleFunction;
19 /**
20 * Returns middleware that parses all bodies as a Buffer and only looks at requests
21 * where the Content-Type header matches the type option.
22 */
23 raw(options?: Options): NextHandleFunction;
24
25 /**
26 * Returns middleware that parses all bodies as a string and only looks at requests
27 * where the Content-Type header matches the type option.
28 */
29 text(options?: OptionsText): NextHandleFunction;
30 /**
31 * Returns middleware that only parses urlencoded bodies and only looks at requests
32 * where the Content-Type header matches the type option
33 */
34 urlencoded(options?: OptionsUrlencoded): NextHandleFunction;
35 }
36
37 interface Options {
38 /** When set to true, then deflated (compressed) bodies will be inflated; when false, deflated bodies are rejected. Defaults to true. */
39 inflate?: boolean | undefined;
40 /**
41 * Controls the maximum request body size. If this is a number,
42 * then the value specifies the number of bytes; if it is a string,
43 * the value is passed to the bytes library for parsing. Defaults to '100kb'.
44 */
45 limit?: number | string | undefined;
46 /**
47 * The type option is used to determine what media type the middleware will parse
48 */
49 type?: string | string[] | ((req: http.IncomingMessage) => any) | undefined;
50 /**
51 * The verify option, if supplied, is called as verify(req, res, buf, encoding),
52 * where buf is a Buffer of the raw request body and encoding is the encoding of the request.
53 */
54 verify?(req: http.IncomingMessage, res: http.ServerResponse, buf: Buffer, encoding: string): void;
55 }
56
57 interface OptionsJson extends Options {
58 /**
59 * The reviver option is passed directly to JSON.parse as the second argument.
60 */
61 reviver?(key: string, value: any): any;
62 /**
63 * When set to `true`, will only accept arrays and objects;
64 * when `false` will accept anything JSON.parse accepts. Defaults to `true`.
65 */
66 strict?: boolean | undefined;
67 }
68
69 interface OptionsText extends Options {
70 /**
71 * Specify the default character set for the text content if the charset
72 * is not specified in the Content-Type header of the request.
73 * Defaults to `utf-8`.
74 */
75 defaultCharset?: string | undefined;
76 }
77
78 interface OptionsUrlencoded extends Options {
79 /**
80 * The extended option allows to choose between parsing the URL-encoded data
81 * with the querystring library (when `false`) or the qs library (when `true`).
82 */
83 extended?: boolean | undefined;
84 /**
85 * The parameterLimit option controls the maximum number of parameters
86 * that are allowed in the URL-encoded data. If a request contains more parameters than this value,
87 * a 413 will be returned to the client. Defaults to 1000.
88 */
89 parameterLimit?: number | undefined;
90 }
91}
92
93declare const bodyParser: bodyParser.BodyParser;
94
95export = bodyParser;
96
\No newline at end of file