mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-29 00:51:29 +08:00
Added type declarations for raw-body
This commit is contained in:
38
raw-body/index.d.ts
vendored
Normal file
38
raw-body/index.d.ts
vendored
Normal 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;
|
||||
27
raw-body/raw-body-tests.ts
Normal file
27
raw-body/raw-body-tests.ts
Normal 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
19
raw-body/tsconfig.json
Normal 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
1
raw-body/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Reference in New Issue
Block a user