From de5e62b604d5782ea23ab7046219318288081204 Mon Sep 17 00:00:00 2001 From: Stefan Reichel Date: Sun, 27 Nov 2016 00:25:00 +0100 Subject: [PATCH 1/2] Added type declarations for accepts --- accepts/accepts-tests.ts | 25 +++++++++++++++++++++++++ accepts/index.d.ts | 31 +++++++++++++++++++++++++++++++ accepts/tsconfig.json | 19 +++++++++++++++++++ accepts/tslint.json | 1 + 4 files changed, 76 insertions(+) create mode 100644 accepts/accepts-tests.ts create mode 100644 accepts/index.d.ts create mode 100644 accepts/tsconfig.json create mode 100644 accepts/tslint.json 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..e6ee4d09f6 --- /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" } From bb5139697e1c603d33e72112d35c4b4656e73135 Mon Sep 17 00:00:00 2001 From: Stefan Reichel Date: Sun, 27 Nov 2016 02:40:14 +0100 Subject: [PATCH 2/2] Fixed missing semicolon. --- accepts/index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/accepts/index.d.ts b/accepts/index.d.ts index e6ee4d09f6..8b5817ce3f 100644 --- a/accepts/index.d.ts +++ b/accepts/index.d.ts @@ -10,19 +10,19 @@ declare namespace accepts { export interface Accepts { charset(charsets: string[]): string | string[] | boolean; charset(...charsets: string[]): string | string[] | boolean; - charsets(): string[] + charsets(): string[]; encoding(encodings: string[]): string | string[] | boolean; encoding(...encodings: string[]): string | string[] | boolean; - encodings(): string[] + encodings(): string[]; language(languages: string[]): string | string[] | boolean; language(...languages: string[]): string | string[] | boolean; - languages(): string[] + languages(): string[]; type(types: string[]): string | string[] | boolean; type(...types: string[]): string | string[] | boolean; - types(): string[] + types(): string[]; } }