本文整理匯總了TypeScript中url.URL.toString方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript URL.toString方法的具體用法?TypeScript URL.toString怎麽用?TypeScript URL.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類url.URL
的用法示例。
在下文中一共展示了URL.toString方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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());
}
示例2: 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;
}
示例3: 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);
}
});
示例4: 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);
示例5: 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;
}
示例6: 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();
}),
示例7: 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();
});
}
示例8: assert
}
{
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';
myURL.hostname = 'example.com';
myURL.href = 'http://other.com';
myURL.hash = 'baz';
myURL.password = "otherpwd";
myURL.username = "otheruser";
myURL.pathname = "/otherPath";
myURL.port = "82";
myURL.protocol = "http";
myURL.search = "a=b";
assert.equal(myURL.href, 'http://otheruser:otherpwd@other.com:82/otherPath?a=b#baz');
myURL = new url.URL('/foo', 'https://example.org/');
示例9: executeAsync
public async executeAsync() {
const response = new HttpResponseMessage(MOVED_TEMPORARILY);
response.headers.location = this.location.toString();
return response;
}
示例10: createWindow
function createWindow(connectionAtShutdown?: SerializableConnection) {
// Create the browser window.
mainWindow = new BrowserWindow({width: 360, height: 640, resizable: false});
const pathToIndexHtml = path.join(app.getAppPath(), '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.info(`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;
});
const minimizeWindowToTray = (event: Event) => {
if (!mainWindow || isAppQuitting) {
return;
}
event.preventDefault(); // Prevent the app from exiting on the 'close' event.
mainWindow.hide();
};
mainWindow.on('minimize', minimizeWindowToTray);
mainWindow.on('close', minimizeWindowToTray);
// TODO: is this the most appropriate event?
mainWindow.webContents.on('did-finish-load', () => {
mainWindow!.webContents.send('localizationRequest', Object.keys(localizedStrings));
interceptShadowsocksLink(process.argv);
if (connectionAtShutdown) {
console.info(`was connected at shutdown, reconnecting to ${connectionAtShutdown.id}`);
sendConnectionStatus(ConnectionStatus.RECONNECTING, connectionAtShutdown.id);
startVpn(connectionAtShutdown.config, connectionAtShutdown.id, true)
.then(
() => {
console.log(`reconnected to ${connectionAtShutdown.id}`);
},
(e) => {
console.error(`could not reconnect: ${e.name} (${e.message})`);
});
}
});
// 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();
});
}