本文整理汇总了TypeScript中url.format函数的典型用法代码示例。如果您正苦于以下问题:TypeScript format函数的具体用法?TypeScript format怎么用?TypeScript format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了format函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: createWindow
function createWindow() {
// Create the browser window.
win = new BrowserWindow({ width: 800, height: 600 });
// and load the index.html of the app.
win.loadURL(
url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true
})
);
// Open the DevTools.
win.webContents.openDevTools();
// Emitted when the window is closed.
win.on("closed", () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
});
protocol.registerBufferProtocol("dictp", async (request, callback) => {
const urlContents = request.url.substr(8).split(":");
const type = urlContents[0]; // image/audio/lookup
if (type === "image" || type === "audio") {
await loadResources(request, callback);
} else if (type === "lookup") {
}
});
}
开发者ID:searene,项目名称:lantastic,代码行数:33,代码来源:Main.ts
示例2: createWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 1000,
height: 700,
frame: false
});
// and load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true
}));
// Open the DevTools.
mainWindow.webContents.openDevTools();
//mainWindow.setResizable(false);
// Emitted when the window is closed.
mainWindow.on("closed", function () {
// Dereference the window object, susually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
}
开发者ID:14rau,项目名称:projekt_01,代码行数:29,代码来源:main.ts
示例3: normalize
export async function normalize(url: Url): Promise<URLInfo> {
const originalURLString = format(url);
const redirects: ExtendedRedirectInfo[] = [];
let outerRedirected = false;
let count = 0;
const redirecters = [rewrite , wd2ed, redirect];
do {
outerRedirected = false;
for (const redirecter of redirecters) {
let innerRedirected = false;
do {
const extRedirectInfo = await redirecter.normalize(url);
// if a redirecter doesn't redirect the url, exit inner loop
if (!extRedirectInfo) {
break;
}
innerRedirected = handleRedirect(url, extRedirectInfo);
if (innerRedirected) {
extRedirectInfo.to = format(url);
redirects.push(extRedirectInfo);
// if a redirecter redirects the url, run other redirecters (outer loop)
outerRedirected = true;
}
// avoid inifenite loop
count++;
if (count > 10) {
console.error(originalURLString, count);
break;
}
} while (innerRedirected);
// avoid inifenite loop
if (count > 10) {
break;
}
}
} while (outerRedirected);
return {
url: format(url),
redirects: redirects,
};
}
开发者ID:takenspc,项目名称:ps-url-normalizer,代码行数:47,代码来源:index.ts
示例4: relativeURL
export function relativeURL(base: string, url: string) {
// 忽略 data:... 等 URI
if (/^[\w+\-\.\+]+:(?!\/)/.test(url)) {
return url
}
const baseObject = parse(base, false, true)
const urlObject = parse(url, false, true)
// 协议不同,只能使用绝对路径
if (baseObject.protocol !== urlObject.protocol) {
return format(urlObject)
}
// 协议相同但主机(含端口)或用户名(含密码)不同,使用省略协议的绝对路径
if (baseObject.host !== urlObject.host || baseObject.auth !== urlObject.auth) {
if (urlObject.slashes) {
delete urlObject.protocol
}
return format(urlObject)
}
// 两个地址必须都是相对路径或都是绝对路径,否则只能使用绝对路径
if (baseObject.pathname && urlObject.pathname && (baseObject.pathname.charCodeAt(0) === 47 /*/*/) !== (urlObject.pathname.charCodeAt(0) === 47 /*/*/)) {
return format(urlObject)
}
// 计算地址开头的相同部分,以 `/` 为界
base = baseObject.pathname ? posix.normalize(baseObject.pathname) : ""
url = urlObject.pathname ? posix.normalize(urlObject.pathname) : ""
let index = -1
let i = 0
for (; i < base.length && i < url.length; i++) {
const ch1 = base.charCodeAt(i)
const ch2 = url.charCodeAt(i)
if (ch1 !== ch2) {
break
}
if (ch1 === 47 /*/*/) {
index = i
}
}
// 重新追加不同的路径部分
let pathname = url.substring(index + 1) || (i === base.length ? "" : ".")
for (let i = index + 1; i < base.length; i++) {
if (base.charCodeAt(i) === 47 /*/*/) {
pathname = pathname === "." ? "../" : `../${pathname}`
}
}
return `${pathname}${urlObject.search || ""}${urlObject.hash || ""}`
}
开发者ID:tpack,项目名称:utilskit,代码行数:46,代码来源:url.ts
示例5: jsonPost
function jsonPost(urlObj, body) {
const urlStr = url.format(urlObj);
return fetchJson(urlStr, {
method: 'post',
body: JSON.stringify(body),
});
}
开发者ID:integer32llc,项目名称:rust-playground,代码行数:8,代码来源:actions.ts
示例6: assign
const mergeQps = (originalUrl: string, opts?: Handlebars.HelperOptions) => {
let u = url.parse(originalUrl, true);
if (opts) {
assign(u.query, opts.hash || {});
}
delete u.search;
return url.format(u);
};
开发者ID:qjac,项目名称:sql-fundamentals,代码行数:8,代码来源:merge-qps.ts
示例7: getCurrentURLWithoutHash
export function getCurrentURLWithoutHash() {
return URL.format({
protocol: window.location.protocol,
host: window.location.host,
pathname: window.location.pathname,
search: window.location.search
});
}
开发者ID:agarwalrounak,项目名称:cbioportal-frontend,代码行数:8,代码来源:urls.ts
示例8: buildCBioPortalPageUrl
export function buildCBioPortalPageUrl(pathnameOrParams:string | BuildUrlParams, query?:QueryParams, hash?:string) {
let params:BuildUrlParams = typeof pathnameOrParams === 'string' ? {pathname: pathnameOrParams, query, hash} : pathnameOrParams;
return URL.format({
protocol: window.location.protocol,
host: AppConfig.baseUrl,
...params
});
}
开发者ID:agarwalrounak,项目名称:cbioportal-frontend,代码行数:8,代码来源:urls.ts
示例9: getNCBIlink
export function getNCBIlink(pathnameOrParams?: BuildUrlParams | string): string {
let params = typeof pathnameOrParams === 'string' ? {pathname: pathnameOrParams} : pathnameOrParams;
return URL.format({
protocol: 'https',
host: 'www.ncbi.nlm.nih.gov',
...params
});
}
开发者ID:agarwalrounak,项目名称:cbioportal-frontend,代码行数:8,代码来源:urls.ts
示例10: getRequestUrl
export function getRequestUrl(req: Request) {
return url.format({
protocol: req.protocol,
host: req.get('host'),
pathname: req.path,
search: querystring.stringify(req.query)
});
}
开发者ID:itsuryev,项目名称:tp-oauth-server,代码行数:8,代码来源:expressUtils.ts
注:本文中的url.format函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论