How to use tldts-core - 10 common examples

To help you get started, we’ve selected a few tldts-core 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 remusao / tldts / packages / tldts-experimental / index.ts View on Github external
import { FLAG, getEmptyResult, IOptions, IResult, parseImpl, resetResult } from 'tldts-core';
import suffixLookup from './src/packed-hashes';

// For all methods but 'parse', it does not make sense to allocate an object
// every single time to only return the value of a specific attribute. To avoid
// this un-necessary allocation, we use a global object which is re-used.
const RESULT: IResult = getEmptyResult();

export function parse(url: string, options: Partial = {}): IResult {
  return parseImpl(url, FLAG.ALL, suffixLookup, options, getEmptyResult());
}

export function getHostname(
  url: string,
  options: Partial = {},
): string | null {
  resetResult(RESULT);
  return parseImpl(url, FLAG.HOSTNAME, suffixLookup, options, RESULT).hostname;
}

export function getPublicSuffix(
  url: string,
  options: Partial = {},
github remusao / tldts / packages / tldts / index.ts View on Github external
import { FLAG, getEmptyResult, IOptions, IResult, parseImpl, resetResult } from 'tldts-core';
import suffixLookup from './src/suffix-trie';

// For all methods but 'parse', it does not make sense to allocate an object
// every single time to only return the value of a specific attribute. To avoid
// this un-necessary allocation, we use a global object which is re-used.
const RESULT: IResult = getEmptyResult();

export function parse(url: string, options: Partial = {}): IResult {
  return parseImpl(url, FLAG.ALL, suffixLookup, options, getEmptyResult());
}

export function getHostname(
  url: string,
  options: Partial = {},
): string | null {
  resetResult(RESULT);
  return parseImpl(url, FLAG.HOSTNAME, suffixLookup, options, RESULT).hostname;
}

export function getPublicSuffix(
  url: string,
  options: Partial = {},
github remusao / tldts / packages / tldts-experimental / src / packed-hashes.ts View on Github external
export default function suffixLookup(
  hostname: string,
  options: ISuffixLookupOptions,
  out: IPublicSuffix,
): void {
  if (fastPathLookup(hostname, options, out) === true) {
    return;
  }

  const { allowIcannDomains, allowPrivateDomains } = options;

  // Keep track of longest match
  let matchIndex = -1;
  let matchKind = Result.NO_MATCH;
  let matchLabels = 0; // Keep track of number of labels currently matched

  // Index in the packed array data-structure
  let index = 1;

  const numberOfHashes = hashHostnameLabelsBackward(
    hostname,
    packed[0] /* maximumNumberOfLabels */,
github remusao / tldts / packages / tldts / index.ts View on Github external
export function getPublicSuffix(
  url: string,
  options: Partial = {},
): string | null {
  resetResult(RESULT);
  return parseImpl(url, FLAG.PUBLIC_SUFFIX, suffixLookup, options, RESULT).publicSuffix;
}
github remusao / tldts / packages / tldts / index.ts View on Github external
export function parse(url: string, options: Partial = {}): IResult {
  return parseImpl(url, FLAG.ALL, suffixLookup, options, getEmptyResult());
}
github remusao / tldts / packages / tldts-experimental / index.ts View on Github external
export function getPublicSuffix(
  url: string,
  options: Partial = {},
): string | null {
  resetResult(RESULT);
  return parseImpl(url, FLAG.PUBLIC_SUFFIX, suffixLookup, options, RESULT).publicSuffix;
}
github remusao / tldts / packages / tldts / index.ts View on Github external
export function getDomain(
  url: string,
  options: Partial = {},
): string | null {
  resetResult(RESULT);
  return parseImpl(url, FLAG.DOMAIN, suffixLookup, options, RESULT).domain;
}
github remusao / tldts / packages / tldts-experimental / index.ts View on Github external
export function getDomain(
  url: string,
  options: Partial = {},
): string | null {
  resetResult(RESULT);
  return parseImpl(url, FLAG.DOMAIN, suffixLookup, options, RESULT).domain;
}
github remusao / tldts / packages / tldts-experimental / index.ts View on Github external
export function getSubdomain(
  url: string,
  options: Partial = {},
): string | null {
  resetResult(RESULT);
  return parseImpl(url, FLAG.SUB_DOMAIN, suffixLookup, options, RESULT).subdomain;
}
github remusao / tldts / packages / tldts-experimental / index.ts View on Github external
export function getHostname(
  url: string,
  options: Partial = {},
): string | null {
  resetResult(RESULT);
  return parseImpl(url, FLAG.HOSTNAME, suffixLookup, options, RESULT).hostname;
}

tldts-core

tldts core primitives (internal module)

MIT
Latest version published 3 days ago

Package Health Score

85 / 100
Full package analysis

Similar packages