How to use the tlds.some function in tlds

To help you get started, we’ve selected a few tlds examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github joelshepherd / tabliss / src / plugins / widgets / search / Search.tsx View on Github external
private buildUrl(query: string) {
    // See if they have started with a web scheme
    if (/^https?:\/\/\w+/.test(query)) {
      return query;
    }

    // See if they have ended with a valid TLD
    if (tlds.some(tld => query.endsWith(`.${tld}`))) {
      return `https://${query}`;
    }

    // Probably searching then
    const searchEngine =
      engines.find(engine => engine.key === this.props.data!.searchEngine) ||
      engines[0];

    return searchEngine.search_url.replace('{searchTerms}', query);
  }
github joelshepherd / tabliss / src / plugins / widgets / search / utils.ts View on Github external
export function buildUrl(query: string, engineUrl: string) {
  // See if they have started with a web scheme
  if (/^https?:\/\/\w+/.test(query)) {
    return query;
  }

  // See if they have ended with a valid TLD
  if (tlds.some(tld => query.endsWith(`.${tld}`))) {
    return `https://${query}`;
  }

  // Probably searching then
  return engineUrl.replace('{searchTerms}', encodeURIComponent(query));
}

tlds

A list of TLDs.

MIT
Latest version published 1 month ago

Package Health Score

75 / 100
Full package analysis