本文整理匯總了TypeScript中url.URL類的典型用法代碼示例。如果您正苦於以下問題:TypeScript URL類的具體用法?TypeScript URL怎麽用?TypeScript URL使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了URL類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getWebAppUrl
function getWebAppUrl() {
const queryParams = new url.URLSearchParams();
queryParams.set('version', electron.app.getVersion());
// Set queryParams from environment variables.
if (process.env.SB_IMAGE) {
queryParams.set('image', process.env.SB_IMAGE);
console.log(`Will install Shadowbox from ${process.env.SB_IMAGE} Docker image`);
}
if (process.env.SB_METRICS_URL) {
queryParams.set('metricsUrl', process.env.SB_METRICS_URL);
console.log(`Will use metrics url ${process.env.SB_METRICS_URL}`);
}
if (process.env.SENTRY_DSN) {
queryParams.set('sentryDsn', process.env.SENTRY_DSN);
console.log(`Will use sentryDsn url ${process.env.SENTRY_DSN}`);
}
if (debugMode) {
queryParams.set('outlineDebugMode', 'true');
console.log(`Enabling Outline debug mode`);
}
// Append arguments to URL if any.
const webAppUrl = new url.URL('outline://web_app/index.html');
webAppUrl.search = queryParams.toString();
const webAppUrlString = webAppUrl.toString();
console.log('Launching web app from ' + webAppUrlString);
return webAppUrlString;
}
示例2: URL
return new Promise<string>((resolve, reject) => {
try {
const parsedUrl = new URL(url);
const header = this.authenticator.getHeader();
parsedUrl.searchParams.set('Authorization', header.Authorization);
resolve(parsedUrl.toString());
} catch (e) {
reject(e);
}
});
示例3: updateWebsite
async function updateWebsite(spinner: Ora): Promise<number> {
spinner.start();
if (await hasChanges()) {
spinner.fail('Please reset your local changes before running this script');
return 1;
}
let pkg = await readPackage();
let latestVersion = await getLatestVersion(pkg);
let currentRevision = await gitRevParse('HEAD');
let remote = 'origin';
spinner.text = 'Building';
await run('yarn', ['build']);
spinner.text = 'Switching to website branch';
let githubToken = process.env['GH_TOKEN'];
if (githubToken) {
let remoteURL = new URL((await run('git', ['remote', 'get-url', remote])).stdout.trim());
remoteURL.username = githubToken;
remoteURL.password = '';
await run('git', ['remote', 'set-url', remote, remoteURL.toString()]);
}
await run('git', ['fetch', remote, `+refs/heads/gh-pages:refs/remotes/${remote}/gh-pages`]);
await run('git', ['reset', '--hard', `${remote}/gh-pages`]);
spinner.text = 'Creating browser build';
await run('browserify',[
'--standalone', 'esnext',
'--require', `./${pkg.main}`,
'--outfile', 'esnext.js'
]);
if (await hasChanges()) {
if (commit) {
spinner.text = 'Pushing changes to website';
await run('git', ['commit', '-av', '-m', `chore: update to v${latestVersion}`]);
await run('git', ['push', '--force', remote, 'HEAD:gh-pages']);
spinner.succeed('Website published');
} else {
console.log((await run('git', ['diff'])).stdout);
}
} else {
spinner.succeed('Already up to date');
}
await run('git', ['reset', '--hard', currentRevision]);
return 0;
}
示例4: redirect
function redirect(response: express.Response, baseURL: URL, params: {[key: string]: any}) {
let url = new URL(baseURL.toString());
for (let key in params) {
if (!params.hasOwnProperty(key)) {
continue;
}
if (typeof params[key] !== 'undefined') {
url.searchParams.set(key, params[key].toString());
}
}
response.redirect(url.toString());
}
示例5: map
map(partialUrl => {
if (!partialUrl) {
partialUrl = 'https://registry.npmjs.org/';
}
const partial = url.parse(partialUrl);
let fullUrl = new url.URL(`http://${partial.host}/${packageName.replace(/\//g, '%2F')}`);
try {
const registry = new url.URL(partialUrl);
registry.pathname = (registry.pathname || '')
.replace(/\/?$/, '/' + packageName.replace(/\//g, '%2F'));
fullUrl = new url.URL(url.format(registry));
} catch {}
logger.debug(
`Getting package.json from '${packageName}' (url: ${JSON.stringify(fullUrl)})...`,
);
return fullUrl.toString();
}),
示例6: return
return (function _annotate(obj: any, scope: string): any {
if (isRef(obj)) {
const uri = new URL(obj.$ref, scope);
uri.hash = '#'
getMeta(obj).refs.add(uri.toString());
obj[__meta].scope = normalizeUri(scope);
} else {
if (typeof obj.$id === 'string') {
if (!obj.$id || obj.$id === '#') {
throw new SyntaxError(`Invalid identifier ${obj.$id}`);
}
const id = new URL(obj.$id, scope);
if (id.hash) {
if (!id.hash.substr(1).match(LII_RE)) {
throw new SyntaxError(`Invalid identifier ${obj.$id}`);
}
} else {
id.hash = '#';
}
obj[__meta].scope = id.toString();
obj[__meta].registry[obj[__meta].scope] = obj;
obj[__meta].root = obj;
} else {
obj[__meta].scope = normalizeUri(scope);
}
const keys = Object.keys(obj);
for (let key of keys) {
const next = obj[key];
if (next !== null && typeof next === 'object' && !isAnnotated(next)) {
const meta = getMeta(obj);
next[__meta] = {
registry: meta.registry,
refs: meta.refs,
parent: obj,
root: meta.root
}
_annotate(next, `${meta.scope}/${escape(key)}`);
}
}
}
return obj;
})(obj, options.scope);
示例7: addUrl
public addUrl(url: URL | string) {
if (typeof url === 'string') {
if (!url.match(protocolRegExp)) {
url = `${this.defaultProtocol()}${url}`;
}
url = new URL(url);
}
this.urls.push(url);
}
示例8: createWindow
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 360, height: 640, resizable: false, icon: iconPath});
const pathToIndexHtml = path.join(__dirname, '..', 'www', 'electron_index.html');
const webAppUrl = new url.URL(`file://${pathToIndexHtml}`);
// Debug mode, etc.
const queryParams = new url.URLSearchParams();
if (debugMode) {
queryParams.set('debug', 'true');
}
webAppUrl.search = queryParams.toString();
const webAppUrlAsString = webAppUrl.toString();
console.log(`loading web app from ${webAppUrlAsString}`);
mainWindow.loadURL(webAppUrlAsString);
// Emitted when the window is closed.
mainWindow.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.
mainWindow = null;
});
// TODO: is this the most appropriate event?
mainWindow.webContents.on('did-finish-load', () => {
interceptShadowsocksLink(process.argv);
});
// The client is a single page app - loading any other page means the
// user clicked on one of the Privacy, Terms, etc., links. These should
// open in the user's browser.
mainWindow.webContents.on('will-navigate', (event: Event, url: string) => {
shell.openExternal(url);
event.preventDefault();
});
}
示例9: getBoolean
function getBoolean(): boolean { return false; }
const urlUrl = url.parse('http://example.com/?hello=world', getBoolean());
if (typeof(urlUrl.query) === 'string') {
queryStr = urlUrl.query;
} else if (urlUrl.query) {
helloQuery = urlUrl.query['hello'];
}
}
{
const ascii: string = url.domainToASCII('espaĂąol.com');
const unicode: string = url.domainToUnicode('xn--espaol-zwa.com');
}
{
let myURL = new url.URL('https://theuser:thepwd@example.org:81/foo/path?query=string#bar');
assert.equal(myURL.hash, '#bar');
assert.equal(myURL.host, 'example.org:81');
assert.equal(myURL.hostname, 'example.org');
assert.equal(myURL.href, 'https://theuser:thepwd@example.org:81/foo/path?query=string#bar');
assert.equal(myURL.origin, 'https://example.org:81');
assert.equal(myURL.password, 'thepwd');
assert.equal(myURL.username, 'theuser');
assert.equal(myURL.pathname, '/foo/path');
assert.equal(myURL.port, "81");
assert.equal(myURL.protocol, "https:");
assert.equal(myURL.search, "?query=string");
assert.equal(myURL.toString(), 'https://theuser:thepwd@example.org:81/foo/path?query=string#bar');
assert(myURL.searchParams instanceof url.URLSearchParams);
myURL.host = 'example.org:82';
示例10: executeAsync
public async executeAsync() {
const response = new HttpResponseMessage(MOVED_TEMPORARILY);
response.headers.location = this.location.toString();
return response;
}