當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript url.URL類代碼示例

本文整理匯總了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;
}
開發者ID:fang2x,項目名稱:outline-server,代碼行數:29,代碼來源:index.ts

示例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);
   }
 });
開發者ID:wix,項目名稱:media-platform-js-sdk,代碼行數:10,代碼來源:http-client.ts

示例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;
}
開發者ID:alangpierce,項目名稱:esnext,代碼行數:53,代碼來源:update-website.ts

示例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());
}
開發者ID:jdiazmx,項目名稱:gateway,代碼行數:12,代碼來源:oauth_controller.ts

示例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();
    }),
開發者ID:iwe7,項目名稱:devkit,代碼行數:19,代碼來源:npm.ts

示例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);
開發者ID:vivocha,項目名稱:jsonref,代碼行數:42,代碼來源:meta.ts

示例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);
  }
開發者ID:chrisseg,項目名稱:vscode-azure-blockchain-ethereum,代碼行數:11,代碼來源:Consortium.ts

示例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();
  });
}
開發者ID:fang2x,項目名稱:outline-client,代碼行數:40,代碼來源:index.ts

示例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';
開發者ID:Lavoaster,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:node-tests.ts

示例10: 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


注:本文中的url.URL類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。