Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix isPrivate being undefined #2

Merged
merged 1 commit into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Change Log

### *not released*
- [#2](https://github.com/remusao/tldts/pull/2) Fix isPrivate being undefined

### 3.0.2 (2018/10/03 15h46)

- [#6](https://github.com/remusao/tldts/pull/6) Update Public Suffix Lists
Expand Down
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.

86 changes: 43 additions & 43 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 === false;
if (step === FLAG.PUBLIC_SUFFIX) { return result; }

// Extract domain
Expand Down