How to use the tldts-experimental.parse function in tldts-experimental

To help you get started, we’ve selected a few tldts-experimental 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 cliqz-oss / adblocker / packages / adblocker-puppeteer / adblocker.ts View on Github external
private onFrame = async (frame: puppeteer.Frame): Promise => {
    // DOM features
    const { ids, hrefs, classes } = await frame.$$eval(
      '[id],[class],[href]',
      extractFeaturesFromDOM,
    );

    // Source features
    const url = frame.url();
    const parsed = parse(url);
    const hostname = parsed.hostname || '';
    const domain = parsed.domain || '';

    // Get cosmetics to inject into the Frame
    const { active, scripts, styles } = this.getCosmeticsFilters({
      domain,
      hostname,
      url,

      // DOM information
      classes,
      hrefs,
      ids,
    });

    // Abort if cosmetics are disabled
github cliqz-oss / adblocker / packages / adblocker / src / request.ts View on Github external
public static fromRawDetails({
    requestId = '0',
    tabId = 0,
    url = '',
    hostname,
    domain,
    sourceUrl = '',
    sourceHostname,
    sourceDomain,
    type = 'main_frame',
  }: Partial): Request {
    url = url.toLowerCase();

    if (hostname === undefined || domain === undefined) {
      const parsed = parse(url, TLDTS_OPTIONS);
      hostname = hostname || parsed.hostname || '';
      domain = domain || parsed.domain || '';
    }

    // Initialize source URL
    if (sourceHostname === undefined || sourceDomain === undefined) {
      const parsed = parse(sourceUrl, TLDTS_OPTIONS);
      sourceHostname = sourceHostname || parsed.hostname || '';
      sourceDomain = sourceDomain || parsed.domain || '';
    }

    // source URL
    return new Request({
      requestId,
      tabId,
github cliqz-oss / adblocker / packages / adblocker-webextension / adblocker.ts View on Github external
private onRuntimeMessage = (
    msg: IBackgroundCallback & { action?: string },
    sender: chrome.runtime.MessageSender,
    sendResponse: (response?: any) => void,
  ): void => {
    if (sender.tab === undefined || sender.tab.id === undefined || sender.frameId === undefined) {
      return;
    }

    // Make sure we only listen to messages coming from our content-script
    // based on the value of `action`.
    if (msg.action === 'getCosmeticsFilters') {
      // Extract hostname from sender's URL
      const { url = '', frameId } = sender;
      const parsed = parse(url);
      const hostname = parsed.hostname || '';
      const domain = parsed.domain || '';

      // Once per tab/page load we inject base stylesheets. These are always
      // the same for all frames of a given page because they do not depend on
      // a particular domain and cannot be cancelled using unhide rules.
      // Because of this, we specify `allFrames: true` when injecting them so
      // that we do not need to perform this operation for sub-frames.
      if (frameId === 0 && msg.lifecycle === 'start') {
        const { active, styles } = this.getCosmeticsFilters({
          domain,
          hostname,
          url,

          classes: msg.classes,
          hrefs: msg.hrefs,
github cliqz-oss / adblocker / packages / adblocker / src / request.ts View on Github external
sourceUrl = '',
    sourceHostname,
    sourceDomain,
    type = 'main_frame',
  }: Partial): Request {
    url = url.toLowerCase();

    if (hostname === undefined || domain === undefined) {
      const parsed = parse(url, TLDTS_OPTIONS);
      hostname = hostname || parsed.hostname || '';
      domain = domain || parsed.domain || '';
    }

    // Initialize source URL
    if (sourceHostname === undefined || sourceDomain === undefined) {
      const parsed = parse(sourceUrl, TLDTS_OPTIONS);
      sourceHostname = sourceHostname || parsed.hostname || '';
      sourceDomain = sourceDomain || parsed.domain || '';
    }

    // source URL
    return new Request({
      requestId,
      tabId,

      domain,
      hostname,
      url,

      sourceDomain,
      sourceHostname,
      sourceUrl,
github cliqz-oss / adblocker / packages / adblocker-electron / adblocker.ts View on Github external
private onGetCosmeticFilters = (
    event: Electron.IpcMainEvent,
    url: string,
    msg: IBackgroundCallback,
  ): void => {
    // Extract hostname from sender's URL
    const parsed = parse(url);
    const hostname = parsed.hostname || '';
    const domain = parsed.domain || '';

    const { active, styles, scripts } = this.getCosmeticsFilters({
      domain,
      hostname,
      url,

      classes: msg.classes,
      hrefs: msg.hrefs,
      ids: msg.ids,

      // This needs to be done only once per frame
      getBaseRules: msg.lifecycle === 'start',
      getInjectionRules: msg.lifecycle === 'start',
      getRulesFromHostname: msg.lifecycle === 'start',
github cliqz-oss / adblocker / packages / adblocker-benchmarks / blockers / tldts_baseline.js View on Github external
match({ url, frameUrl }) {
    return parse(url) && parse(frameUrl);
  }
};
github cliqz / url-parser / lib / url.ts View on Github external
get domainInfo() {
    if (!this._domainInfo) {
      this._domainInfo = parse(this.hostname, {
        extractHostname: false,
      });
    }
    return this._domainInfo;
  }

tldts-experimental

Library to work against complex domain names, subdomains and URIs.

MIT
Latest version published 5 days ago

Package Health Score

80 / 100
Full package analysis