From 05d4b1ab4c09ec82f203e6494adf203de7e4b883 Mon Sep 17 00:00:00 2001 From: newraina Date: Tue, 21 Feb 2017 10:17:31 +0800 Subject: [PATCH] add d.ts for fetch.io package --- fetch.io/fetch.io-tests.ts | 60 +++++++++++++++++++++++++++ fetch.io/index.d.ts | 85 ++++++++++++++++++++++++++++++++++++++ fetch.io/tsconfig.json | 24 +++++++++++ fetch.io/tslint.json | 1 + 4 files changed, 170 insertions(+) create mode 100644 fetch.io/fetch.io-tests.ts create mode 100644 fetch.io/index.d.ts create mode 100644 fetch.io/tsconfig.json create mode 100644 fetch.io/tslint.json diff --git a/fetch.io/fetch.io-tests.ts b/fetch.io/fetch.io-tests.ts new file mode 100644 index 0000000000..4e14a7a9a9 --- /dev/null +++ b/fetch.io/fetch.io-tests.ts @@ -0,0 +1,60 @@ + +import Fetch from 'fetch.io' + +const request = new Fetch() + +request + .get('') + .query({}) + .json() + +request + .delete('') + .json() + +request + .head('') + .json() + +request + .options('') + .json() + +request + .put('') + .json() + +request + .config('key', 'value') + .json() + +request + .config({key: 'value'}) + .json() + +request + .config('set', 'value') + .json() + +request + .set({key: 'value'}) + .json() + +request + .type('json') + .json() + +request + .get('') + .query({}) + .text() + +request + .get('') + .query({}) + .then(() => {}) + +request + .post('') + .send({}) + .json() diff --git a/fetch.io/index.d.ts b/fetch.io/index.d.ts new file mode 100644 index 0000000000..8a6755d7c5 --- /dev/null +++ b/fetch.io/index.d.ts @@ -0,0 +1,85 @@ +// Type definitions for fetch.io v3.1.4 +// Project: https://github.com/haoxins/fetch.io +// Definitions by: newraina +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + + type TUrl = string + + type TMethod = 'delete' | 'get' | 'head' | 'options' | 'post' | 'put' + + interface IQuery { + [key: string]: number | boolean | string + } + + interface IHeader { + [key: string]: string + } + + interface IOptions extends RequestInit { + + prefix?: string + + query?: IQuery + + header?: IHeader + + beforeRequest?(url: TUrl, body: BodyInit): boolean + + afterResponse?(res: Response): void + + afterJSON?(body: any): void + } + + declare namespace FetchIo { + + class Request { + + constructor(method: TMethod, url: TUrl, options: IOptions) + + delete: (url: TUrl) => this + + get: (url: TUrl) => this + + head: (url: TUrl) => this + + options: (url: TUrl) => this + + post: (url: TUrl) => this + + put: (url: TUrl) => this + + config(key: string, value: any): this + + config(opts: {[key: string]: any}): this + + set(key: string, value: any): this + + set(opts: {[key: string]: any}): this + + type(type: 'json' | 'form' | 'urlencoded'): this + + query(object: {[key: string]: any}): this + + send(data: {[key: string]: any}): this + + append(key: string, value: string): this + + then(resolve: (value?: Response) => void, reject?: (reason?: any) => void): Promise + + then(resolve: (value?: Response) => void, reject?: (reason?: any) => void): Promise + + json(strict?: boolean): Promise + + json(strict?: boolean): Promise + + text(): Promise + + text(): Promise + } + + class Fetch extends Request { + constructor(options?: IOptions) + } +} + +export = FetchIo.Fetch diff --git a/fetch.io/tsconfig.json b/fetch.io/tsconfig.json new file mode 100644 index 0000000000..44013e849a --- /dev/null +++ b/fetch.io/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "allowSyntheticDefaultImports": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "fetch.io-tests.ts" + ] +} diff --git a/fetch.io/tslint.json b/fetch.io/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/fetch.io/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }