diff --git a/body-parser/index.d.ts b/body-parser/index.d.ts index b8a1b0dc86..4627c2c5b3 100644 --- a/body-parser/index.d.ts +++ b/body-parser/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for body-parser // Project: http://expressjs.com -// Definitions by: Santi Albo , VILIC VANE , Jonathan Häberle +// Definitions by: Santi Albo , VILIC VANE , Jonathan Häberle , Gevik Babakhani // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -41,7 +41,14 @@ declare function bodyParser(options?: { }): express.RequestHandler; declare namespace bodyParser { - export function json(options?: { + + /** + * Interface for defining the options for the json() middleware + * + * @export + * @interface JsonOptions + */ + export interface JsonOptions { /** * if deflated bodies will be inflated. (default: true) */ @@ -66,9 +73,15 @@ declare namespace bodyParser { * passed to JSON.parse(). */ reviver?: (key: string, value: any) => any; - }): express.RequestHandler; + } - export function raw(options?: { + /** + * Interface for defining the options the raw() middleware + * + * @export + * @interface RawOptions + */ + export interface RawOptions { /** * if deflated bodies will be inflated. (default: true) */ @@ -85,9 +98,15 @@ declare namespace bodyParser { * function to verify body content, the parsing can be aborted by throwing an error. */ verify?: (req: express.Request, res: express.Response, buf: Buffer, encoding: string) => void; - }): express.RequestHandler; + } - export function text(options?: { + /** + * Interface for defining the options for the text() middleware + * + * @export + * @interface TextOptions + */ + export interface TextOptions { /** * if deflated bodies will be inflated. (default: true) */ @@ -108,9 +127,15 @@ declare namespace bodyParser { * the default charset to parse as, if not specified in content-type. (default: 'utf-8') */ defaultCharset?: string; - }): express.RequestHandler; + } - export function urlencoded(options: { + /** + * Interface for defining the options for the urlencoded() middleware + * + * @export + * @interface UrlEncodedOptions + */ + export interface UrlEncodedOptions { /** * if deflated bodies will be inflated. (default: true) */ @@ -131,7 +156,47 @@ declare namespace bodyParser { * parse extended syntax with the qs module. */ extended: boolean; - }): express.RequestHandler; + } + + /** + * Returns middleware that only parses json. This parser accepts any Unicode encoding + * of the body and supports automatic inflation of gzip and deflate encodings. + * + * @export + * @param {JsonOptions} [options] + * @returns {express.RequestHandler} + */ + export function json(options?: JsonOptions): express.RequestHandler; + + /** + * Returns middleware that parses all bodies as a Buffer. This parser supports automatic + * inflation of gzip and deflate encodings. + * + * @export + * @param {RawOptions} [options] + * @returns {express.RequestHandler} + */ + export function raw(options?: RawOptions): express.RequestHandler; + + /** + * Returns middleware that parses all bodies as a string. This parser supports + * automatic inflation of gzip and deflate encodings. + * + * @export + * @param {TextOptions} [options] + * @returns {express.RequestHandler} + */ + export function text(options?: TextOptions): express.RequestHandler; + + /** + * Returns middleware that only parses urlencoded bodies. This parser accepts only + * UTF-8 encoding of the body and supports automatic inflation of gzip and deflate encodings. + * + * @export + * @param {UrlEncodedOptions} [options] + * @returns {express.RequestHandler} + */ + export function urlencoded(options?: UrlEncodedOptions): express.RequestHandler; } export = bodyParser;