當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript url.format函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。