UNPKG

1.83 kBTypeScriptView Raw
1/// <reference types="express" />
2import { Options, OptionsJson, OptionsText, OptionsUrlencoded } from 'body-parser';
3import { HttpError } from 'http-errors';
4import { Request, RequestBodyParserOptions, Response } from '../types';
5/**
6 * Get the content-type header value from the request
7 * @param req - Http request
8 */
9export declare function getContentType(req: Request): string | undefined;
10/**
11 * Express body parser function type
12 */
13export type BodyParserMiddleware = (request: Request, response: Response, next: (err: HttpError) => void) => void;
14/**
15 * Normalize parsing errors as `4xx`
16 * @param err
17 */
18export declare function normalizeParsingError(err: HttpError): HttpError<number>;
19/**
20 * Parse the request body asynchronously
21 * @param handle - The express middleware handler
22 * @param request - Http request
23 */
24export declare function invokeBodyParserMiddleware(handle: BodyParserMiddleware, request: Request): Promise<any>;
25export declare const DEFAULT_LIMIT = "1mb";
26/**
27 * Extract parser options based on the parser type
28 * @param type - json|urlencoded|text
29 * @param options
30 */
31export declare function getParserOptions(type: 'json', options: RequestBodyParserOptions): OptionsJson;
32export declare function getParserOptions(type: 'urlencoded', options: RequestBodyParserOptions): OptionsUrlencoded;
33export declare function getParserOptions(type: 'text', options: RequestBodyParserOptions): OptionsText;
34export declare function getParserOptions(type: 'raw', options: RequestBodyParserOptions): Options;
35export declare namespace builtinParsers {
36 const json: unique symbol;
37 const urlencoded: unique symbol;
38 const text: unique symbol;
39 const raw: unique symbol;
40 const stream: unique symbol;
41 const names: (string | symbol)[];
42 const mapping: {
43 [name: string]: symbol;
44 };
45}