UNPKG

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