Added type declarations for raw-body

This commit is contained in:
Stefan Reichel
2016-11-27 02:32:53 +01:00
parent 3e9ed9d35f
commit 1af21196f1
4 changed files with 85 additions and 0 deletions

38
raw-body/index.d.ts vendored Normal file
View File

@@ -0,0 +1,38 @@
// 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 interface 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;

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
raw-body/tsconfig.json Normal file
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
raw-body/tslint.json Normal file
View File

@@ -0,0 +1 @@
{ "extends": "../tslint.json" }