Merge pull request #12932 from Bomret/raw-body

Added types declarations for raw-body
This commit is contained in:
Paul van Brenk
2016-11-29 15:28:42 -08:00
committed by GitHub
4 changed files with 83 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
// Type definitions for raw-body
// Project: https://github.com/stream-utils/raw-body
// Definitions by: Stefan Reichel <https://github.com/bomret>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
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<string | Buffer>;
export = getRawBody;
+27
View File
@@ -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);
});
+19
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "../tslint.json" }