Skip to content

Commit

Permalink
- Added interface definitions for middleware parameters
Browse files Browse the repository at this point in the history
- Added JSDoc where possible
- Made the "options" parameters for the urlencoded() optional
  • Loading branch information
blendsdk committed Feb 17, 2017
1 parent 3177c01 commit b0345b4
Showing 1 changed file with 74 additions and 9 deletions.
83 changes: 74 additions & 9 deletions body-parser/index.d.ts
@@ -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


Expand Down Expand Up @@ -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)
*/
Expand All @@ -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)
*/
Expand All @@ -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)
*/
Expand All @@ -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)
*/
Expand All @@ -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;

0 comments on commit b0345b4

Please sign in to comment.