mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-31 11:40:47 +08:00
Add type definitions for Qajax
This commit is contained in:
@@ -336,6 +336,7 @@ All definitions files include a header with the author and editors, so at some p
|
||||
* [ProgressJs](http://usablica.github.io/progress.js/) (by [Shunsuke Ohtani](https://github.com/zaneli))
|
||||
* [promise-pool](https://github.com/vilic/promise-pool) (by [VILIC VANE](https://github.com/vilic))
|
||||
* [Q](https://github.com/kriskowal/q) (by Barrie Nemetchek, Andrew Gaspar)
|
||||
* [Qajax](https://github.com/gre/qajax) (by [Boltmade](https://github.com/Boltmade))
|
||||
* [Q-io](https://github.com/kriskowal/q-io) (by [Bart van der Schoor](https://github.com/Bartvds))
|
||||
* [q-retry](https://github.com/vilic/q-retry) (by [VILIC VANE](https://github.com/vilic))
|
||||
* [QUnit](http://qunitjs.com/) (by [Diullei Gomes](https://github.com/Diullei))
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/// <reference path="qajax.d.ts" />
|
||||
|
||||
// Based on https://github.com/gre/qajax/blob/master/test/qajax.js
|
||||
|
||||
function resetDefaults () {
|
||||
Qajax.defaults.logs = true;
|
||||
Qajax.defaults.timeout = 1000;
|
||||
Qajax.defaults.method = "GET";
|
||||
Qajax.defaults.headers = {};
|
||||
Qajax.defaults.base = "";
|
||||
}
|
||||
|
||||
var sample01url = "/test/dataset/sample01.json";
|
||||
var sample01json = [
|
||||
{ "name": "Jerome", "age": 20 },
|
||||
{ "name": "Gerard", "age": 30 },
|
||||
{ "name": "Martine", "age": 43 }
|
||||
];
|
||||
|
||||
var emptyUrl = "/test/dataset/empty";
|
||||
|
||||
function urlWithOptions (url : string, options : any) {
|
||||
return url+"?"+Qajax.serialize(options);
|
||||
}
|
||||
|
||||
Qajax;
|
||||
Qajax.filterStatus;
|
||||
Qajax.filterSuccess;
|
||||
Qajax.getJSON;
|
||||
Qajax.serialize({ foo: 123, bar: "toto" });
|
||||
Qajax.getJSON(sample01url).then((res) => true, (err) => true);
|
||||
Qajax(sample01url).then(Qajax.filterSuccess).then(Qajax.toJSON);
|
||||
Qajax(emptyUrl, { params: { status: 404 } }).then(Qajax.filterSuccess).then(Qajax.toJSON);
|
||||
Qajax({method: "POST", url: "/ECHO", data: "1234567890\nazerty\nuiopqsdfghjklm\nwxcvbn\n"}).then(Qajax.filterSuccess);
|
||||
Qajax({method: "POST", url: "/ECHO", data: { foo: 123, bar: { value: 42 }, arr: [1, 2, 3] }}).then(Qajax.filterSuccess).then(Qajax.toJSON);
|
||||
Qajax({ url: emptyUrl, params: { status: 201 } }).then(Qajax.filterStatus(200));
|
||||
Qajax({method: "POST", url: emptyUrl, params: { status: 500 }}).then(Qajax.filterSuccess).then(Qajax.toJSON);
|
||||
|
||||
var cancellationD = Q.defer();
|
||||
var cancellation = cancellationD.promise;
|
||||
Qajax({ cancellation: cancellation, url: urlWithOptions(emptyUrl, { latency: 400 }) }).then(Qajax.filterSuccess).then(Qajax.toJSON);
|
||||
|
||||
Qajax.defaults.timeout = 200;
|
||||
Qajax({method: "DELETE", url: sample01url, params: { latency: 500 }});
|
||||
|
||||
resetDefaults();
|
||||
Qajax({method: "POST", url: sample01url, params: { latency: 300 }, timeout: 2000});
|
||||
|
||||
Qajax.defaults.timeout = 200;
|
||||
Qajax({method: "DELETE", url: sample01url, params: { latency: 500 }, timeout: 0});
|
||||
|
||||
resetDefaults();
|
||||
Qajax({headers: { "X-Hello": "world" }, method: "GET", url: "/ECHO_HEADERS"}).then(Qajax.filterSuccess).then(Qajax.toJSON);
|
||||
Qajax({headers: { "X-Hi": "world" }, method: "GET", url: "/ECHO_HEADERS"}).then(Qajax.filterSuccess).then(Qajax.toJSON);
|
||||
Qajax.defaults.headers = {"X-Foo": "bar"};
|
||||
Qajax({method: "GET", url: "/ECHO_HEADERS"}).then(Qajax.filterSuccess).then(Qajax.toJSON);
|
||||
|
||||
resetDefaults();
|
||||
Qajax("sample01.json", {base: "/test/dataset/"}).then(Qajax.filterSuccess).then(Qajax.toJSON);
|
||||
Qajax.defaults.base = "/test/dataset/";
|
||||
Qajax("empty").then(Qajax.filterSuccess);
|
||||
|
||||
resetDefaults();
|
||||
Qajax.defaults.method = "POST";
|
||||
Qajax("/ECHO", { data: "1234567890\nazerty\nuiopqsdfghjklm\nwxcvbn\n", responseType: "text/plain" }).then(Qajax.filterSuccess);
|
||||
|
||||
resetDefaults();
|
||||
Qajax.getJSON(urlWithOptions(sample01url, { latency: 50 })).then((res) => true, (err) => true, () => true);
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
// Type definitions for Qajax
|
||||
// Project: https://github.com/gre/qajax
|
||||
// Definitions by: Boltmade <https://github.com/Boltmade>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../q/Q.d.ts" />
|
||||
|
||||
declare function Qajax(url : string) : Q.Promise<XMLHttpRequest>;
|
||||
declare function Qajax(options : any) : Q.Promise<XMLHttpRequest>;
|
||||
declare function Qajax(url : string, options : any) : Q.Promise<XMLHttpRequest>;
|
||||
|
||||
declare module Qajax {
|
||||
export var defaults : any;
|
||||
export function filterStatus(validStatus : number) : (xhr : XMLHttpRequest) => Q.Promise<XMLHttpRequest>;
|
||||
export function filterStatus(validStatus : (status : number) => boolean) : (xhr : XMLHttpRequest) => Q.Promise<XMLHttpRequest>;
|
||||
export function filterSuccess() : Q.Promise<XMLHttpRequest>;
|
||||
|
||||
export function toJSON(xhr : XMLHttpRequest) : Q.Promise<any>;
|
||||
|
||||
export function getJSON(url : string) : Q.Promise<any>;
|
||||
|
||||
export function serialize(paramsObj : any) : string;
|
||||
}
|
||||
|
||||
declare module "qajax" {
|
||||
export = Qajax;
|
||||
}
|
||||
Reference in New Issue
Block a user