当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript util.join函数代码示例

本文整理汇总了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);
        }
    });
开发者ID:GordonSmith,项目名称:Visualization,代码行数:35,代码来源:connection.ts

示例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;
         });
 })
开发者ID:GordonSmith,项目名称:Visualization,代码行数:10,代码来源:connection.ts

示例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");
 });
开发者ID:GordonSmith,项目名称:Visualization,代码行数:9,代码来源:url.spec.ts

示例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));
             }
         });
 });
开发者ID:jchambers-ln,项目名称:Visualization,代码行数:47,代码来源:connection.ts

示例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));
         }
     });
 });
开发者ID:jchambers-ln,项目名称:Visualization,代码行数:43,代码来源:connection.ts

示例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;
                });
        })
    );
}
开发者ID:GordonSmith,项目名称:Visualization,代码行数:38,代码来源:connection.ts


注:本文中的@hpcc-js/util.join函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。