本文整理汇总了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;
}
示例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);
},
示例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({});
}
}
示例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;
}
},
示例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);
}
示例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
)}`
);
}
});
示例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;
}
},