mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 15:57:13 +00:00
Merge pull request #14493 from tlaziuk/body-parser
[body-parser] update to v1.16
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import * as express from 'express';
|
||||
import {
|
||||
json,
|
||||
raw,
|
||||
text,
|
||||
urlencoded,
|
||||
} from 'body-parser';
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(json());
|
||||
app.use(raw());
|
||||
app.use(text());
|
||||
app.use(urlencoded());
|
||||
|
||||
// send any data, it should be parsed and printed
|
||||
app.all('/', (req, res, next) => {
|
||||
console.log(req.body);
|
||||
res.json(req.body);
|
||||
});
|
||||
|
||||
app.listen(8080);
|
||||
Vendored
+25
-179
@@ -1,202 +1,48 @@
|
||||
// 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/>, Gevik Babakhani <https://github.com/blendsdk/>
|
||||
// Type definitions for body-parser 1.16
|
||||
// Project: https://github.com/expressjs/body-parser
|
||||
// Definitions by: Santi Albo <https://github.com/santialbo>, Vilic Vane <https://github.com/vilic>, Jonathan Häberle <https://github.com/dreampulse>, Gevik Babakhani <https://github.com/blendsdk/>, Tomasz Łaziuk <https://github.com/tlaziuk>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import { Request, RequestHandler, Response } from 'express';
|
||||
|
||||
// for docs go to https://github.com/expressjs/body-parser/tree/1.16.0#body-parser
|
||||
|
||||
import * as express from "express";
|
||||
|
||||
/**
|
||||
* bodyParser: use individual json/urlencoded middlewares
|
||||
* @deprecated
|
||||
*/
|
||||
|
||||
declare function bodyParser(options?: {
|
||||
/**
|
||||
* if deflated bodies will be inflated. (default: true)
|
||||
*/
|
||||
inflate?: boolean;
|
||||
/**
|
||||
* maximum request body size. (default: '100kb')
|
||||
*/
|
||||
limit?: any;
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* only parse objects and arrays. (default: true)
|
||||
*/
|
||||
strict?: boolean;
|
||||
/**
|
||||
* passed to JSON.parse().
|
||||
*/
|
||||
reviver?: (key: string, value: any) => any;
|
||||
/**
|
||||
* parse extended syntax with the qs module. (default: true)
|
||||
*/
|
||||
extended?: boolean;
|
||||
}): express.RequestHandler;
|
||||
// @deprecated
|
||||
declare function bodyParser(options?: bodyParser.OptionsJson & bodyParser.OptionsText & bodyParser.OptionsUrlencoded): RequestHandler;
|
||||
|
||||
declare namespace bodyParser {
|
||||
|
||||
/**
|
||||
* Interface for defining the options for the json() middleware
|
||||
*
|
||||
* @export
|
||||
* @interface JsonOptions
|
||||
*/
|
||||
export interface JsonOptions {
|
||||
/**
|
||||
* if deflated bodies will be inflated. (default: true)
|
||||
*/
|
||||
export interface Options {
|
||||
inflate?: boolean;
|
||||
/**
|
||||
* maximum request body size. (default: '100kb')
|
||||
*/
|
||||
limit?: any;
|
||||
/**
|
||||
* request content-type to parse, passed directly to the type-is library. (default: 'json')
|
||||
*/
|
||||
type?: any;
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* only parse objects and arrays. (default: true)
|
||||
*/
|
||||
limit?: number | string;
|
||||
type?: string | ((req: Request) => any);
|
||||
verify?: (req: Request, res: Response, buf: Buffer, encoding: string) => void;
|
||||
}
|
||||
|
||||
export interface OptionsJson extends Options {
|
||||
reviever?: (key: string, value: any) => any;
|
||||
strict?: boolean;
|
||||
/**
|
||||
* passed to JSON.parse().
|
||||
*/
|
||||
reviver?: (key: string, value: any) => any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for defining the options the raw() middleware
|
||||
*
|
||||
* @export
|
||||
* @interface RawOptions
|
||||
*/
|
||||
export interface RawOptions {
|
||||
/**
|
||||
* if deflated bodies will be inflated. (default: true)
|
||||
*/
|
||||
inflate?: boolean;
|
||||
/**
|
||||
* maximum request body size. (default: '100kb')
|
||||
*/
|
||||
limit?: any;
|
||||
/**
|
||||
* request content-type to parse, passed directly to the type-is library. (default: 'application/octet-stream')
|
||||
*/
|
||||
type?: any;
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for defining the options for the text() middleware
|
||||
*
|
||||
* @export
|
||||
* @interface TextOptions
|
||||
*/
|
||||
export interface TextOptions {
|
||||
/**
|
||||
* if deflated bodies will be inflated. (default: true)
|
||||
*/
|
||||
inflate?: boolean;
|
||||
/**
|
||||
* maximum request body size. (default: '100kb')
|
||||
*/
|
||||
limit?: any;
|
||||
/**
|
||||
* request content-type to parse, passed directly to the type-is library. (default: 'text/plain')
|
||||
*/
|
||||
type?: any;
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* the default charset to parse as, if not specified in content-type. (default: 'utf-8')
|
||||
*/
|
||||
export interface OptionsText extends Options {
|
||||
defaultCharset?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for defining the options for the urlencoded() middleware
|
||||
*
|
||||
* @export
|
||||
* @interface UrlEncodedOptions
|
||||
*/
|
||||
export interface UrlEncodedOptions {
|
||||
/**
|
||||
* if deflated bodies will be inflated. (default: true)
|
||||
*/
|
||||
inflate?: boolean;
|
||||
/**
|
||||
* maximum request body size. (default: '100kb')
|
||||
*/
|
||||
limit?: any;
|
||||
/**
|
||||
* request content-type to parse, passed directly to the type-is library. (default: 'urlencoded')
|
||||
*/
|
||||
type?: any;
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* parse extended syntax with the qs module.
|
||||
*/
|
||||
extended: boolean;
|
||||
export interface OptionsUrlencoded extends Options {
|
||||
extended?: boolean;
|
||||
parameterLimit?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
export function json(options?: OptionsJson): 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;
|
||||
export function raw(options?: Options): 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;
|
||||
export function text(options?: OptionsText): RequestHandler;
|
||||
|
||||
export function urlencoded(options?: OptionsUrlencoded): 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;
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
@@ -16,6 +17,7 @@
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts"
|
||||
"index.d.ts",
|
||||
"body-parser-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "../tslint.json",
|
||||
"rules": {
|
||||
"max-line-length": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user