diff --git a/raw-body/index.d.ts b/raw-body/index.d.ts new file mode 100644 index 0000000000..ffe61856c8 --- /dev/null +++ b/raw-body/index.d.ts @@ -0,0 +1,36 @@ +// Type definitions for raw-body +// Project: https://github.com/stream-utils/raw-body +// Definitions by: Stefan Reichel +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +import { Readable } from "stream"; + +declare namespace getRawBody { + export interface Options { + length?: number; + limit?: number; + encoding?: string; + } + + export interface RawBodyError extends Error { + limit?: number; + length?: number; + expected?: number; + received?: number; + encoding?: string; + status?: number; + statusCode?: number; + type?: string; + } + + export type Callback = (err: RawBodyError, res: string | Buffer) => void; +} + + +declare function getRawBody(stream: Readable, callback: getRawBody.Callback): void; +declare function getRawBody(stream: Readable, options: getRawBody.Options | string, callback: getRawBody.Callback): void; + +declare function getRawBody(stream: Readable, options?: getRawBody.Options | string): Promise; + +export = getRawBody; diff --git a/raw-body/raw-body-tests.ts b/raw-body/raw-body-tests.ts new file mode 100644 index 0000000000..f23160c876 --- /dev/null +++ b/raw-body/raw-body-tests.ts @@ -0,0 +1,27 @@ +import getRawBody = require("raw-body"); + +const stream: any = {}; + +const simple = getRawBody(stream); + +const withEncoding = getRawBody(stream, "utf-8"); + +const withOptions = getRawBody(stream, { + encoding: "utf-8", + length: 1024, + limit: 512 +}); + +getRawBody(stream, (err, res) => { + if(err) console.error(err); + else console.log(res); +}); + +getRawBody(stream, { + encoding: "utf-8", + length: 1024, + limit: 512 +}, (err, res) => { + if(err) console.error(err); + else console.log(res); +}); diff --git a/raw-body/tsconfig.json b/raw-body/tsconfig.json new file mode 100644 index 0000000000..d7a3d0c387 --- /dev/null +++ b/raw-body/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "raw-body-tests.ts" + ] +} diff --git a/raw-body/tslint.json b/raw-body/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/raw-body/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }