diff --git a/accepts/accepts-tests.ts b/accepts/accepts-tests.ts new file mode 100644 index 0000000000..7d9c5a8240 --- /dev/null +++ b/accepts/accepts-tests.ts @@ -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"]); diff --git a/accepts/index.d.ts b/accepts/index.d.ts new file mode 100644 index 0000000000..8b5817ce3f --- /dev/null +++ b/accepts/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for accepts +// Project: https://github.com/jshttp/accepts +// Definitions by: Stefan Reichel +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +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; diff --git a/accepts/tsconfig.json b/accepts/tsconfig.json new file mode 100644 index 0000000000..8adaf7363b --- /dev/null +++ b/accepts/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", + "accepts-tests.ts" + ] +} diff --git a/accepts/tslint.json b/accepts/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/accepts/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }