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


TypeScript url.parse函数代码示例

本文整理汇总了TypeScript中common/util/url.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: transformUrl

export function transformUrl(original: string): string {
  if (/^about:/.test(original)) {
    return original;
  }

  let req = original;
  const searchUrl = (q: string) => {
    return "https://duckduckgo.com/?" + querystring.stringify({ q, kae: "d" });
  };

  // special search URLs
  if (/^\?/.test(original)) {
    return searchUrl(original.substr(1));
  }

  // spaces and no dots ? smells like a search request
  if (original.indexOf(" ") !== -1 && original.indexOf(".") === -1) {
    return searchUrl(original);
  }

  // add http: if needed
  let parsed = urlParser.parse(req);
  if (!isWellKnownProtocol(parsed.protocol)) {
    req = "http://" + original;
    parsed = urlParser.parse(req);
    if (!parsed.hostname) {
      return searchUrl(original);
    }
  }

  return req;
}
开发者ID:itchio,项目名称:itch,代码行数:32,代码来源:navigation.ts

示例2: decodeURI

      (request, callback) => {
        const urlPath = url.parse(request.url).pathname;
        const decodedPath = decodeURI(urlPath);
        const rootlessPath = decodedPath.replace(/^\//, "");
        const filePath = join(fileRoot, rootlessPath);

        callback(filePath);
      },
开发者ID:HorrerGames,项目名称:itch,代码行数:8,代码来源:itch-internal.ts

示例3: callback

 (details, callback) => {
   let parsed = url.parse(details.url);
   // resources in `//` will be loaded using itch-cave, we need to
   // redirect them to https for it to work - note this only happens with games
   // that aren't fully offline-mode compliant
   if (parsed.protocol === "itch-cave:" && parsed.host !== "game.itch") {
     callback({
       redirectURL: details.url.replace(/^itch-cave:/, "https:"),
     });
   } else {
     callback({});
   }
 }
开发者ID:HorrerGames,项目名称:itch,代码行数:13,代码来源:itch-internal.ts

示例4: switch

 onRequest: details => {
   let parsed = url.parse(details.url);
   switch (parsed.pathname.replace(/^\//, "")) {
     case "exit-fullscreen":
       win.setFullScreen(false);
       break;
     case "toggle-fullscreen":
       win.setFullScreen(!win.isFullScreen());
       break;
     case "open-devtools":
       win.webContents.openDevTools({ mode: "detach" });
       break;
     default:
       break;
   }
 },
开发者ID:HorrerGames,项目名称:itch,代码行数:16,代码来源:perform-html-launch.ts

示例5: buildLoginAndReturnUrl

function buildLoginAndReturnUrl(returnTo: string): string {
  const parsed = url.parse(returnTo);
  const hostname = url.subdomainToDomain(parsed.hostname);

  let urlOpts: url.UrlWithParsedQuery = {
    hostname,
    pathname: "/login",
    query: { return_to: returnTo },
  };

  if (hostname === "itch.io") {
    urlOpts.protocol = "https";
  } else {
    urlOpts.port = parsed.port;
    urlOpts.protocol = parsed.protocol;
  }

  return url.format(urlOpts);
}
开发者ID:HorrerGames,项目名称:itch,代码行数:19,代码来源:purchases.ts

示例6: callback

    session.webRequest.onBeforeRequest(internalFilter, (details, callback) => {
      callback({ cancel: true });

      let parsed = urlParser.parse(details.url);
      const { pathname, query } = parsed;
      const params = flattenQuery(querystring.parse(query));
      const { tab } = params;

      logger.debug(`Got itch-internal request ${pathname}?${query} for ${tab}`);

      if (pathname === "/open-devtools") {
        store.dispatch(actions.openDevTools({ forApp: false }));
      } else {
        logger.warn(
          `Got unrecognized message via itch-internal: ${pathname}, params ${JSON.stringify(
            params
          )}`
        );
      }
    });
开发者ID:HorrerGames,项目名称:itch,代码行数:20,代码来源:itch-internal.ts

示例7: decodeURI

      (request, callback) => {
        const urlPath = url.parse(request.url).pathname;
        const decodedPath = decodeURI(urlPath);
        const rootlessPath = decodedPath.replace(/^\//, "");
        const filePath = join(fileRoot, rootlessPath);

        try {
          var stats = statSync(filePath);
          var stream = createReadStream(filePath);
          callback({
            headers: {
              server: "itch",
              "content-type": mime.lookup(filePath),
              "content-length": stats.size,
              "access-control-allow-origin": "*",
            },
            statusCode: 200,
            data: stream as any, // *sigh*
          });
        } catch (e) {
          logger.warn(`while serving ${request.url}, got ${e.stack}`);
          let statusCode = 400;
          switch (e.code) {
            case "ENOENT":
              statusCode = 404;
              break;
            case "EPERM":
              statusCode = 401;
              break;
          }

          callback({
            headers: {},
            statusCode,
            data: null,
          });
          return;
        }
      },
开发者ID:itchio,项目名称:itch,代码行数:39,代码来源:itch-cave-protocol.ts


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