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


TypeScript url.URLSearchParams类代码示例

本文整理汇总了TypeScript中url.URLSearchParams的典型用法代码示例。如果您正苦于以下问题:TypeScript URLSearchParams类的具体用法?TypeScript URLSearchParams怎么用?TypeScript URLSearchParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了URLSearchParams类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: test

test("decode a cookie", () => {
    const { data, signature } = parseCookie(sampleCookie);
    expect(signature.length).toBe(684);

    const params = new URLSearchParams(data);
    
    expect(params.get("firstName")).toBe("Test");
    expect(params.get("lastName")).toBe("User");
});
开发者ID:guardian,项目名称:pan-domain-authentication,代码行数:9,代码来源:utils.test.ts

示例2: it

    it('should query users', async () => {
      const headers = {cookie: state.userCookie}
      const queryParams = new URLSearchParams({
        'email[$match]': 'foo.*bar',
        accountId: state.account.id,
      })

      const response = await fetch(`${state.baseURL}/v1/users?${queryParams.toString()}`, {
        headers,
      })
      expect(await response.json()).toHaveProperty('total', 3)
    })
开发者ID:patrickhulce,项目名称:klay,代码行数:12,代码来源:create-many-users.test.ts

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

示例4: urlWithParams

 urlWithParams(newParams: { [key: string]: any }): string {
   const params = new URLSearchParams(this._query);
   for (const k of Object.keys(newParams)) {
     const v = newParams[k];
     if (v) {
       params.set(k, v);
     } else {
       params.delete(k);
     }
   }
   const queryString = params.toString();
   return format({
     protocol: this._protocol,
     hostname: this._hostname,
     pathname: this._pathname,
     slashes: true,
     search: queryString == "" ? null : `?${queryString}`,
   });
 }
开发者ID:itchio,项目名称:itch,代码行数:19,代码来源:space.ts

示例5: parseUser

export function parseUser(data: string): User {
    const params = new URLSearchParams(data);

    function stringField(name: string): string {
        const value = params.get(name);
        if(!value ) { throw new Error(`Missing ${name}`) }

        return value;
    }

    function numberField(name: string): number {
        const value = params.get(name);
        if(!value) { throw new Error(`Missing ${name}`) }

        return parseInt(value);
    }

    function booleanField(name: string): boolean {
        return params.get(name) === 'true';
    }

    function stringListField(name: string): string[] {
        const value = params.get(name);
        if(!value) { throw new Error(`Missing ${name}`) }

        return value.split(",");
    }

    const avatarUrl = params.get("avatarUrl");

    return {
        firstName: stringField("firstName"),
        lastName: stringField("lastName"),
        email: stringField("email"),
        avatarUrl: avatarUrl ? avatarUrl : undefined,
        authenticatingSystem: stringField("system"),
        authenticatedIn: stringListField("authedIn"),
        expires: numberField("expires"),
        multifactor: booleanField("multifactor")
    };
}
开发者ID:guardian,项目名称:pan-domain-authentication,代码行数:41,代码来源:utils.ts

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

示例7:

        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/');
        assert.equal(myURL.href, 'https://example.org/foo');
        assert.equal(myURL.toJSON(), myURL.href);
    }

    {
        const searchParams = new url.URLSearchParams('abc=123');

        assert.equal(searchParams.toString(), 'abc=123');
        searchParams.forEach((value: string, name: string, me: url.URLSearchParams): void => {
            assert.equal(name, 'abc');
            assert.equal(value, '123');
            assert.equal(me, searchParams);
        });

        assert.equal(searchParams.get('abc'), '123');

        searchParams.append('abc', 'xyz');

        assert.deepEqual(searchParams.getAll('abc'), ['123', 'xyz']);

        const entries = searchParams.entries();
开发者ID:Lavoaster,项目名称:DefinitelyTyped,代码行数:31,代码来源:node-tests.ts

示例8: 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.URLSearchParams类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。