本文整理汇总了TypeScript中@library/utility/appUtils.formatUrl函数的典型用法代码示例。如果您正苦于以下问题:TypeScript formatUrl函数的具体用法?TypeScript formatUrl怎么用?TypeScript formatUrl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了formatUrl函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: mountSwagger
export function mountSwagger() {
SwaggerUIBundle({
deepLinking: true,
dom_id: "#swagger-ui",
// layout: "DashboardLayout",
plugins: [SwaggerUIBundle.plugins.DownloadUrl],
presets: [SwaggerUIBundle.presets.apis],
requestInterceptor: (request: Request) => {
request.headers["x-transient-key"] = getMeta("TransientKey");
return request;
},
url: formatUrl("/api/v2/open-api/v3" + window.location.search),
validatorUrl: null,
});
}
示例2: it
it("follows the given format", () => {
application.setMeta("context.basePath", "/test");
expect(application.formatUrl("/discussions")).eq("/test/discussions");
});
示例3: expect
paths.forEach(path => {
expect(application.formatUrl(path)).eq(path);
});
示例4: dispatch
.then((response: AxiosResponse) => {
dispatch(authenticatePasswordActions.success(response, params));
const urlParms = new URLSearchParams();
window.location.href = formatUrl(urlParms.get("target") || "/");
})
示例5: callback
const remoteDataHandler = (query, callback) => {
// Do this because of undefined when adding spaces to
// matcher callback, as it will be monitoring changes.
query = query || "";
// Only all query strings greater than min_characters
if (query.length >= minCharacters) {
// If the cache array contains less than LIMIT 30
// (according to server logic), then there's no
// point sending another request to server, as there
// won't be any more results, as this is the maximum.
let shouldContinueFiltering = true;
// Remove last character so that the string can be
// found in the cache, if exists, then check if its
// matching array has less than the server limit of
// matches, which means there are no more, so save the
// additional server request from being sent.
let filterString = "";
// Loop through string and find first closest match in
// the cache, and if a match, check if more filtering
// is required.
for (let i = 0, l = query.length; i < l; i++) {
filterString = query.slice(0, -i);
if (atCache[filterString] && atCache[filterString].length < serverLimit) {
// Add this other query to empty array, so that it
// will not fire off another request.
atEmpty[query] = query;
// Do not filter more, meaning, do not send
// another server request, as all the necessary
// data is already in memory.
shouldContinueFiltering = false;
break;
}
}
// Check if query would be empty, based on previously
// cached empty results. Compare against the start of
// the latest query string.
let isQueryEmpty = false;
// Loop through cache of empty query strings.
for (const key in atEmpty) {
if (atEmpty.hasOwnProperty(key)) {
// See if cached empty results match the start
// of the latest query. If so, then no point
// sending new request, as it will return empty.
if (query.match(new RegExp("^" + key + "+")) !== null) {
isQueryEmpty = true;
break;
}
}
}
const filterSuccessHandler = data => {
if (Array.isArray(data)) {
data.forEach(result => {
if (typeof result === "object" && typeof result.name === "string") {
// Convert special characters to safely insert into template.
result.name = result.name
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
});
}
callback(data);
// If data is empty, cache the results to prevent
// other requests against similarly-started
// query strings.
if (data.length) {
atCache[query] = data;
} else {
atEmpty[query] = query;
}
};
// Produce the suggestions based on data either
// cached or retrieved.
if (shouldContinueFiltering && !isQueryEmpty && !atCache[query]) {
$.getJSON(
formatUrl("/user/tagsearch"),
{
q: query,
limit: serverLimit,
},
filterSuccessHandler,
);
} else {
// If no point filtering more as the parent filter
// has not been maxed out with responses, use the
// closest parent filter instead of the latest
// query string.
//.........这里部分代码省略.........
示例6: fieldErrorTransformer
import axios, { AxiosResponse, AxiosRequestConfig } from "axios";
import qs from "qs";
import { sprintf } from "sprintf-js";
import { humanFileSize } from "@library/utility/fileUtils";
import { IApiError, IFieldError } from "@library/@types/api/core";
function fieldErrorTransformer(responseData) {
if (responseData && responseData.status >= 400 && responseData.errors && responseData.errors.length > 0) {
responseData.errors = indexArrayByKey(responseData.errors, "field");
}
return responseData;
}
const apiv2 = axios.create({
baseURL: formatUrl("/api/v2/"),
headers: {
common: {
"X-Requested-With": "vanilla",
},
},
transformResponse: [...(axios.defaults.transformResponse as any), fieldErrorTransformer],
paramsSerializer: params => qs.stringify(params),
});
export default apiv2;
export type ProgressHandler = (progressEvent: any) => void;
export function createTrackableRequest(
requestFunction: (progressHandler: ProgressHandler) => () => Promise<AxiosResponse>,