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


TypeScript URL.toString方法代码示例

本文整理汇总了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());
}
开发者ID:jdiazmx,项目名称:gateway,代码行数:12,代码来源:oauth_controller.ts

示例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;
}
开发者ID:fang2x,项目名称:outline-server,代码行数:29,代码来源:index.ts

示例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);
   }
 });
开发者ID:wix,项目名称:media-platform-js-sdk,代码行数:10,代码来源:http-client.ts

示例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);
开发者ID:vivocha,项目名称:jsonref,代码行数:42,代码来源:meta.ts

示例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;
}
开发者ID:alangpierce,项目名称:esnext,代码行数:53,代码来源:update-website.ts

示例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();
    }),
开发者ID:iwe7,项目名称:devkit,代码行数:19,代码来源:npm.ts

示例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();
  });
}
开发者ID:fang2x,项目名称:outline-client,代码行数:40,代码来源:index.ts

示例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/');
开发者ID:Lavoaster,项目名称:DefinitelyTyped,代码行数:31,代码来源:node-tests.ts

示例9: executeAsync

 public async executeAsync() {
     const response = new HttpResponseMessage(MOVED_TEMPORARILY);
     response.headers.location = this.location.toString();
     return response;
 }
开发者ID:inversify,项目名称:inversify-express-utils,代码行数:5,代码来源:RedirectResult.ts

示例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();
  });
}
开发者ID:hlyu368,项目名称:outline-client,代码行数:64,代码来源:index.ts


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