Skip to content

Commit

Permalink
Fix isPrivate being undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
remusao committed Sep 23, 2018
1 parent 9d43b5a commit 2c33d3b
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 64 deletions.
7 changes: 1 addition & 6 deletions dist/lib/public-suffix.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { IOptions } from './options';
import Trie from './suffix-trie';
export interface IPublicSuffix {
isIcann: boolean;
isPrivate: boolean;
publicSuffix: string | null;
}
import Trie, { IPublicSuffix } from './suffix-trie';
export default function getPublicSuffix(rules: Trie, hostname: string, options: IOptions): IPublicSuffix;
7 changes: 6 additions & 1 deletion dist/lib/suffix-trie.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ interface IOptions {
allowIcannDomains: boolean;
allowPrivateDomains: boolean;
}
export interface IPublicSuffix {
isIcann: boolean;
isPrivate: boolean;
publicSuffix: string | null;
}
export interface IRule {
exception: boolean;
isIcann: boolean;
Expand All @@ -16,6 +21,6 @@ export default class SuffixTrie {
rules: ITrieObject;
constructor(rules: IRule[]);
hasTld(value: string): boolean;
suffixLookup(hostname: string, options: IOptions): any;
suffixLookup(hostname: string, options: IOptions): IPublicSuffix | null;
}
export {};
4 changes: 3 additions & 1 deletion dist/tldts.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion dist/tldts.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 46 additions & 46 deletions dist/tldts.min.js

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions lib/public-suffix.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import extractTldFromHost from './from-host';
import { IOptions } from './options';
import Trie from './suffix-trie';

export interface IPublicSuffix {
isIcann: boolean;
isPrivate: boolean;
publicSuffix: string | null;
}
import Trie, { IPublicSuffix } from './suffix-trie';

/**
* Returns the public suffix (including exact matches)
Expand Down
10 changes: 9 additions & 1 deletion lib/suffix-trie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ interface IOptions {
allowPrivateDomains: boolean;
}

export interface IPublicSuffix {
isIcann: boolean;
isPrivate: boolean;
publicSuffix: string | null;
}

// Flags used to know if a rule is ICANN or Private
const enum RULE_TYPE {
ICANN = 1,
Expand Down Expand Up @@ -162,7 +168,7 @@ export default class SuffixTrie {
/**
* Check if `hostname` has a valid public suffix in `trie`.
*/
public suffixLookup(hostname: string, options: IOptions): any {
public suffixLookup(hostname: string, options: IOptions): IPublicSuffix | null {
const allowIcannDomains = options.allowIcannDomains;
const allowPrivateDomains = options.allowPrivateDomains;

Expand Down Expand Up @@ -211,12 +217,14 @@ export default class SuffixTrie {
if (exceptionLookupResult.index !== -1) {
return {
isIcann: exceptionLookupResult.isIcann,
isPrivate: !exceptionLookupResult.isIcann,
publicSuffix: hostnameParts.slice(exceptionLookupResult.index + 1).join('.'),
};
}

return {
isIcann: lookupResult.isIcann,
isPrivate: !lookupResult.isIcann,
publicSuffix: hostnameParts.slice(lookupResult.index).join('.'),
};
}
Expand Down
2 changes: 1 addition & 1 deletion tldts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ function parseImplFactory(trie: Trie = getRules()) {
);

result.publicSuffix = publicSuffixResult.publicSuffix;
result.isPrivate = publicSuffixResult.isPrivate;
result.isIcann = publicSuffixResult.isIcann;
result.isPrivate = !publicSuffixResult.isIcann;
if (step === FLAG.PUBLIC_SUFFIX) { return result; }

// Extract domain
Expand Down

0 comments on commit 2c33d3b

Please sign in to comment.