Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 = {},
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 = {},
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 */,
export function getPublicSuffix(
url: string,
options: Partial = {},
): string | null {
resetResult(RESULT);
return parseImpl(url, FLAG.PUBLIC_SUFFIX, suffixLookup, options, RESULT).publicSuffix;
}
export function parse(url: string, options: Partial = {}): IResult {
return parseImpl(url, FLAG.ALL, suffixLookup, options, getEmptyResult());
}
export function getPublicSuffix(
url: string,
options: Partial = {},
): string | null {
resetResult(RESULT);
return parseImpl(url, FLAG.PUBLIC_SUFFIX, suffixLookup, options, RESULT).publicSuffix;
}
export function getDomain(
url: string,
options: Partial = {},
): string | null {
resetResult(RESULT);
return parseImpl(url, FLAG.DOMAIN, suffixLookup, options, RESULT).domain;
}
export function getDomain(
url: string,
options: Partial = {},
): string | null {
resetResult(RESULT);
return parseImpl(url, FLAG.DOMAIN, suffixLookup, options, RESULT).domain;
}
export function getSubdomain(
url: string,
options: Partial = {},
): string | null {
resetResult(RESULT);
return parseImpl(url, FLAG.SUB_DOMAIN, suffixLookup, options, RESULT).subdomain;
}
export function getHostname(
url: string,
options: Partial = {},
): string | null {
resetResult(RESULT);
return parseImpl(url, FLAG.HOSTNAME, suffixLookup, options, RESULT).hostname;
}