Skip to content

Commit

Permalink
chore: Refactor after merging #70
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnns committed May 28, 2019
1 parent 28d7e4b commit efc2976
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/parseDomain.js
Expand Up @@ -70,8 +70,8 @@ function parseDomain(url, options) {
}

domain = urlSplit[3]; // domain will now be something like sub.domain.example.com

tld = matchTld(domain, normalizedOptions);

if (tld === null) {
return null;
}
Expand All @@ -83,7 +83,9 @@ function parseDomain(url, options) {
// removes the remaining dot, if present (added to handle localhost)
tld = tld.slice(1);
}

domain = urlSplit.pop();

const subdomain = urlSplit.join(".");

return {
Expand Down
9 changes: 4 additions & 5 deletions test/parseDomain.test.js
Expand Up @@ -141,14 +141,13 @@ describe("parseDomain(url)", () => {
it("should return null if the given value is not a string", () => {
expect(parseDomain(undefined)).to.equal(null);
expect(parseDomain({})).to.equal(null);
expect(parseDomain("")).to.equal(null);
expect(parseDomain(" ")).to.equal(null);
expect(parseDomain("\xa0")).to.equal(null);
});

it("should return null if the given value contains invalid characters", () => {
expect(parseDomain("http://hell.d\ne.ibm.com")).to.equal(null);
it("should return null if the given string is not a valid URL", () => {
expect(parseDomain("\xa0")).to.equal(null);
expect(parseDomain("")).to.equal(null);
expect(parseDomain(" ")).to.equal(null);
expect(parseDomain("http://hell.d\ne.ibm.com")).to.equal(null);
});

it("should return null if the given is an empty string with a space character", () => {
Expand Down

0 comments on commit efc2976

Please sign in to comment.