parse-domain 2.3.0 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,129 +0,0 @@
1
- "use strict";
2
-
3
- const fs = require("fs");
4
- const path = require("path");
5
- const chai = require("chai");
6
- const parsePubSuffixList = require("../../lib/tries/parsePubSuffixList");
7
-
8
- const expect = chai.expect;
9
- const pathToFixtures = path.resolve(__dirname, "..", "fixtures");
10
- const icannStart = "// ===BEGIN ICANN DOMAINS===";
11
- const icannEnd = "// ===END ICANN DOMAINS===";
12
- const privateStart = "// ===BEGIN PRIVATE DOMAINS===";
13
- const privateEnd = "// ===END PRIVATE DOMAINS===";
14
-
15
- describe("parsePubSuffixList()", () => {
16
- it("returns an object with empty lists by default", () => {
17
- const str = [icannStart, icannEnd, privateStart, privateEnd].join("\n");
18
-
19
- expect(parsePubSuffixList(str)).to.eql({
20
- icann: [],
21
- private: [],
22
- });
23
- });
24
-
25
- it("splits the list by the line break character \\n (ignoring \\r if present)", () => {
26
- const str = [
27
- icannStart,
28
- "a.b.c\r",
29
- "a",
30
- "b\r",
31
- icannEnd + "\r",
32
- privateStart,
33
- "a.b.c",
34
- "a",
35
- "b",
36
- privateEnd,
37
- ].join("\n");
38
-
39
- expect(parsePubSuffixList(str)).to.eql({
40
- icann: ["a.b.c", "a", "b"],
41
- private: ["a.b.c", "a", "b"],
42
- });
43
- });
44
-
45
- it("removes lines that start with a // sequence", () => {
46
- const str = [
47
- icannStart,
48
- "// comment",
49
- "a.b.c",
50
- "a",
51
- "b",
52
- "//another comment",
53
- icannEnd,
54
- privateStart,
55
- "a.b.c",
56
- "//",
57
- "a",
58
- " // ",
59
- "b",
60
- privateEnd,
61
- ].join("\n");
62
-
63
- expect(parsePubSuffixList(str)).to.eql({
64
- icann: ["a.b.c", "a", "b"],
65
- private: ["a.b.c", "a", "b"],
66
- });
67
- });
68
-
69
- it("removes empty lines", () => {
70
- const str = [
71
- icannStart,
72
- " ",
73
- "a.b.c",
74
- "a",
75
- "b",
76
- "\r",
77
- icannEnd,
78
- privateStart,
79
- "a.b.c",
80
- "\t",
81
- "a",
82
- "b",
83
- privateEnd,
84
- ].join("\n");
85
-
86
- expect(parsePubSuffixList(str)).to.eql({
87
- icann: ["a.b.c", "a", "b"],
88
- private: ["a.b.c", "a", "b"],
89
- });
90
- });
91
-
92
- it("throws when the ICANN start marker is missing ", () => {
93
- const str = [""].join("\n");
94
-
95
- expect(() => parsePubSuffixList(str)).to.throw("Missing start marker of icann list");
96
- });
97
-
98
- it("throws when the ICANN end marker is missing ", () => {
99
- const str = [icannStart].join("\n");
100
-
101
- expect(() => parsePubSuffixList(str)).to.throw("Missing end marker of icann list");
102
- });
103
-
104
- it("throws when the PRIVATE start marker is missing ", () => {
105
- const str = [icannStart, icannEnd].join("\n");
106
-
107
- expect(() => parsePubSuffixList(str)).to.throw("Missing start marker of private list");
108
- });
109
-
110
- it("throws when the PRIVATE end marker is missing ", () => {
111
- const str = [icannStart, icannEnd, privateStart].join("\n");
112
-
113
- expect(() => parsePubSuffixList(str)).to.throw("Missing end marker of private list");
114
- });
115
-
116
- describe("with fixtures", () => {
117
- const pubSuffixList = fs.readFileSync(path.resolve(pathToFixtures, "pubSuffixList.txt"), "utf8");
118
-
119
- it("returns the expected result (based on samples)", () => {
120
- const parsedList = parsePubSuffixList(pubSuffixList);
121
-
122
- expect(parsedList.icann).to.be.an("array");
123
- expect(parsedList.private).to.be.an("array");
124
- expect(parsedList.icann).to.contain("com");
125
- expect(parsedList.icann).to.contain("co.uk");
126
- expect(parsedList.private).to.contain("herokuapp.com");
127
- });
128
- });
129
- });
@@ -1,162 +0,0 @@
1
- "use strict";
2
-
3
- const chai = require("chai");
4
- const parseTrie = require("../../lib/tries/parseTrie");
5
-
6
- const expect = chai.expect;
7
-
8
- describe("parseTrie()", () => {
9
- describe("basic cases", () => {
10
- it("returns a map", () => {
11
- expect(parseTrie("")).to.be.instanceOf(Map);
12
- });
13
-
14
- it("returns an empty map when an empty string is given", () => {
15
- const trie = parseTrie("");
16
-
17
- expect(trie.size).to.equal(0);
18
- });
19
-
20
- it("returns a map with the given domain as key and true as value", () => {
21
- const trie = parseTrie("some-domain");
22
- const someDomain = trie.get("some-domain");
23
-
24
- expect(someDomain).to.equal(true);
25
- });
26
- });
27
-
28
- describe("with SAME separator", () => {
29
- it("returns a map with the given domains as key and true as value", () => {
30
- const trie = parseTrie("a,b,c");
31
- const a = trie.get("a");
32
- const b = trie.get("b");
33
- const c = trie.get("c");
34
-
35
- expect(a).to.equal(true);
36
- expect(b).to.equal(true);
37
- expect(c).to.equal(true);
38
- });
39
- });
40
-
41
- describe("and with DOWN separator", () => {
42
- it("returns a nested map", () => {
43
- const trie = parseTrie("a>a");
44
- const a = trie.get("a");
45
- const aa = a.get("a");
46
-
47
- expect(aa).to.equal(true);
48
- });
49
-
50
- it("returns a deeply nested map", () => {
51
- const trie = parseTrie("a>a>a");
52
- const a = trie.get("a");
53
- const aa = a.get("a");
54
- const aaa = aa.get("a");
55
-
56
- expect(aa).to.be.instanceOf(Map);
57
- expect(aaa).to.equal(true);
58
- });
59
-
60
- it("returns a nested map with the given domains as key and true as value", () => {
61
- const trie = parseTrie("a>a,b,c");
62
- const a = trie.get("a");
63
- const aa = a.get("a");
64
- const ab = a.get("b");
65
- const ac = a.get("c");
66
-
67
- expect(aa).to.equal(true);
68
- expect(ab).to.equal(true);
69
- expect(ac).to.equal(true);
70
- });
71
- });
72
-
73
- describe("and with UP separator", () => {
74
- it("returns a map with maps", () => {
75
- const trie = parseTrie("a>a,b<b>a,b");
76
- const a = trie.get("a");
77
- const aa = a.get("a");
78
- const ab = a.get("a");
79
- const b = trie.get("b");
80
- const ba = b.get("a");
81
- const bb = b.get("b");
82
-
83
- expect(aa).to.equal(true);
84
- expect(ab).to.equal(true);
85
- expect(ba).to.equal(true);
86
- expect(bb).to.equal(true);
87
- });
88
-
89
- it("goes up multiple levels", () => {
90
- const trie = parseTrie("a>a>a>a<<<b");
91
- const a = trie.get("a");
92
- const aa = a.get("a");
93
- const aaa = aa.get("a");
94
- const aaaa = aaa.get("a");
95
- const b = trie.get("b");
96
-
97
- expect(aaaa).to.equal(true);
98
- expect(b).to.equal(true);
99
- });
100
- });
101
-
102
- describe("and with RESET separator", () => {
103
- it("resets the domain level", () => {
104
- const trie = parseTrie("a>a|b");
105
- const a = trie.get("a");
106
- const aa = a.get("a");
107
- const b = trie.get("b");
108
-
109
- expect(aa).to.equal(true);
110
- expect(b).to.equal(true);
111
- });
112
-
113
- it("works also on the top-level", () => {
114
- const trie = parseTrie("a|b");
115
- const a = trie.get("a");
116
- const b = trie.get("b");
117
-
118
- expect(a).to.equal(true);
119
- expect(b).to.equal(true);
120
- });
121
-
122
- it("returns the expected trie", () => {
123
- const trie = parseTrie("a>a>a|b>a|c");
124
- const a = trie.get("a");
125
- const aa = a.get("a");
126
- const aaa = aa.get("a");
127
- const b = trie.get("b");
128
- const ba = b.get("a");
129
- const c = trie.get("c");
130
-
131
- expect(aaa).to.equal(true);
132
- expect(ba).to.equal(true);
133
- expect(c).to.equal(true);
134
- });
135
- });
136
-
137
- describe("complex cases", () => {
138
- it("parses 'a>a>a>a<<b,c|b>a>a<b>a>a,b' without errors", () => {
139
- const trie = parseTrie("a>a>a>a<<b,c|b>a>a<b>a>a,b");
140
- const a = trie.get("a");
141
- const aa = a.get("a");
142
- const aaa = aa.get("a");
143
- const aaaa = aaa.get("a");
144
- const ab = a.get("b");
145
- const ac = a.get("c");
146
- const b = trie.get("b");
147
- const ba = b.get("a");
148
- const baa = ba.get("a");
149
- const bb = b.get("b");
150
- const bba = bb.get("a");
151
- const bbaa = bba.get("a");
152
- const bbab = bba.get("b");
153
-
154
- expect(aaaa).to.equal(true);
155
- expect(ab).to.equal(true);
156
- expect(ac).to.equal(true);
157
- expect(baa).to.equal(true);
158
- expect(bbaa).to.equal(true);
159
- expect(bbab).to.equal(true);
160
- });
161
- });
162
- });