本文整理匯總了TypeScript中@hpcc-js/util.join函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript join函數的具體用法?TypeScript join怎麽用?TypeScript join使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了join函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
return new Promise<any>((resolve, reject) => {
let respondedTimeout = opts.timeoutSecs! * 1000;
const respondedTick = 5000;
const callbackName = "jsonp_callback_" + Math.round(Math.random() * 999999);
(window as any)[callbackName] = function (response: any) {
respondedTimeout = 0;
doCallback();
resolve(responseType === "json" && typeof response === "string" ? deserializeResponse(response) : response);
};
const script = document.createElement("script");
let url = join(opts.baseUrl, action);
url += url.indexOf("?") >= 0 ? "&" : "?";
script.src = url + "jsonp=" + callbackName + "&" + serializeRequest(request);
document.body.appendChild(script);
const progress = setInterval(function () {
if (respondedTimeout <= 0) {
clearInterval(progress);
} else {
respondedTimeout -= respondedTick;
if (respondedTimeout <= 0) {
clearInterval(progress);
logger.error("Request timeout: " + script.src);
doCallback();
reject(Error("Request timeout: " + script.src));
} else {
logger.debug("Request pending (" + respondedTimeout / 1000 + " sec): " + script.src);
}
}
}, respondedTick);
function doCallback() {
delete (window as any)[callbackName];
document.body.removeChild(script);
}
});
示例2: fetch
.catch(e => {
// Try again with the opposite credentials mode ---
requestInit.credentials = !_omitMap[opts.baseUrl] ? "omit" : "include";
return fetch(join(opts.baseUrl, action), requestInit)
.then(handleResponse)
.then(responseBody => {
_omitMap[opts.baseUrl] = !_omitMap[opts.baseUrl]; // The "opposite" credentials mode is known to work ---
return responseBody;
});
})
示例3: it
it("join", function () {
expect(join("aaa", "bbb", "ccc")).to.equal("aaa/bbb/ccc");
expect(join()).to.equal("");
expect(join("aaa")).to.equal("aaa");
expect(join("/aaa")).to.equal("/aaa");
expect(join("/aaa", "bbb", "ccc")).to.equal("/aaa/bbb/ccc");
expect(join("/aaa/", "/bbb/", "/ccc/")).to.equal("/aaa/bbb/ccc");
expect(join("aaa/", "/bbb/", "/ccc/")).to.equal("aaa/bbb/ccc");
});
示例4: Promise
return new Promise((resolve, reject) => {
const options: any = {
method: verb,
uri: join(this._opts.baseUrl, action),
auth: {
user: this._opts.userID,
pass: this._opts.password,
sendImmediately: true
},
username: this._opts.userID,
password: this._opts.password
};
switch (verb) {
case "GET":
options.uri += "?" + this.serialize(request);
break;
case "POST":
options.headers = {
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/x-www-form-urlencoded"
};
options.rejectUnauthorized = this._opts.rejectUnauthorized;
options.body = this.serialize(request);
break;
default:
}
const xhr = _d3Request(options.uri)
.timeout(this._opts.timeoutSecs! * 1000)
;
if (verb === "POST") {
xhr
.header("X-Requested-With", "XMLHttpRequest")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Origin", null)
;
}
xhr
.send(verb, options.body, (err: any, resp: any) => {
if (err) {
reject(new Error(err));
} else if (resp && resp.status === 200) {
resolve(responseType === ResponseType.JSON ? this.deserialize(resp.responseText) : resp.responseText);
} else {
reject(new Error(resp.responseText));
}
});
});
示例5: join
return new Promise<any>((resolve, reject) => {
const options: any = {
method: verb,
uri: join(this._opts.baseUrl, action),
auth: {
user: this._opts.userID,
pass: this._opts.password,
sendImmediately: true
},
username: this._opts.userID,
password: this._opts.password,
timeout: this._opts.timeoutSecs! * 1000
};
// Older ESP versions were not case insensitive ---
const oldESPAuth = `Basic ${btoa(this._opts.userID + ":" + this._opts.password)}`;
switch (verb) {
case "GET":
options.headers = {
Authorization: oldESPAuth
};
options.uri += "?" + this.serialize(request);
break;
case "POST":
options.headers = {
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": oldESPAuth
};
options.rejectUnauthorized = this._opts.rejectUnauthorized;
options.body = this.serialize(request);
break;
default:
}
_nodeRequest(options, (err: any, resp: any, body: any) => {
if (err) {
reject(new Error(err));
} else if (resp && resp.statusCode === 200) {
resolve(responseType === ResponseType.JSON ? this.deserialize(body) : body);
} else {
reject(new Error(body));
}
});
});
示例6: doFetch
function doFetch(opts: IOptions, action: string, requestInit: RequestInit, headersInit: HeadersInit, responseType: string) {
headersInit = {
...authHeader(opts),
...headersInit
};
requestInit = {
credentials: _omitMap[opts.baseUrl] ? "omit" : "include",
...requestInit,
headers: headersInit
};
if (opts.rejectUnauthorized === false && fetch["__agent"] && opts.baseUrl.indexOf("https:") === 0) {
// NodeJS / node-fetch only ---
requestInit["agent"] = fetch["__agent"];
}
function handleResponse(response: Response): Promise<any> {
if (response.ok) {
return responseType === "json" ? response.json() : response.text();
}
throw new Error(response.statusText);
}
return promiseTimeout(opts.timeoutSecs! * 1000, fetch(join(opts.baseUrl, action), requestInit)
.then(handleResponse)
.catch(e => {
// Try again with the opposite credentials mode ---
requestInit.credentials = !_omitMap[opts.baseUrl] ? "omit" : "include";
return fetch(join(opts.baseUrl, action), requestInit)
.then(handleResponse)
.then(responseBody => {
_omitMap[opts.baseUrl] = !_omitMap[opts.baseUrl]; // The "opposite" credentials mode is known to work ---
return responseBody;
});
})
);
}