Merge pull request #12937 from Bomret/accepts

Added type declarations for accept.
This commit is contained in:
Paul van Brenk
2016-11-29 15:33:11 -08:00
committed by GitHub
4 changed files with 76 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
import accepts = require("accepts");
const req: any = {};
const accept = accepts(req);
const charsets = accept.charsets();
const charsetFromEmpty = accept.charset();
const charsetFromParams = accept.charset("json", "text");
const charsetFromArray = accept.charset(["json", "text"]);
const encodings = accept.encodings();
const encodingFromEmpty = accept.encoding();
const encodingFromParams = accept.encoding("json", "text");
const encodingFromArray = accept.encoding(["json", "text"]);
const languages = accept.languages();
const languageFromEmpty = accept.language();
const languageFromParams = accept.language("json", "text");
const languageFromArray = accept.language(["json", "text"]);
const types = accept.types();
const typeFromEmpty = accept.type();
const typeFromParams = accept.type("json", "text");
const typeFromArray = accept.type(["json", "text"]);
+31
View File
@@ -0,0 +1,31 @@
// Type definitions for accepts
// Project: https://github.com/jshttp/accepts
// Definitions by: Stefan Reichel <https://github.com/bomret>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { IncomingMessage } from "http";
declare namespace accepts {
export interface Accepts {
charset(charsets: string[]): string | string[] | boolean;
charset(...charsets: string[]): string | string[] | boolean;
charsets(): string[];
encoding(encodings: string[]): string | string[] | boolean;
encoding(...encodings: string[]): string | string[] | boolean;
encodings(): string[];
language(languages: string[]): string | string[] | boolean;
language(...languages: string[]): string | string[] | boolean;
languages(): string[];
type(types: string[]): string | string[] | boolean;
type(...types: string[]): string | string[] | boolean;
types(): string[];
}
}
declare function accepts(req: IncomingMessage): accepts.Accepts;
export = accepts;
+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",
"accepts-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "../tslint.json" }