- Added interface definitions for middleware parameters

- Added JSDoc where possible
- Made the "options" parameters for the urlencoded() optional
This commit is contained in:
Gevik Babakhani
2017-02-17 12:06:14 +01:00
parent 3177c01620
commit b0345b4d1b

View File

@@ -1,6 +1,6 @@
// Type definitions for body-parser
// Project: http://expressjs.com
// Definitions by: Santi Albo <https://github.com/santialbo/>, VILIC VANE <https://vilic.info>, Jonathan Häberle <https://github.com/dreampulse/>
// Definitions by: Santi Albo <https://github.com/santialbo/>, VILIC VANE <https://vilic.info>, Jonathan Häberle <https://github.com/dreampulse/>, Gevik Babakhani <https://github.com/blendsdk/>
// 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;