parse-domain 0.1.1 → 0.2.2
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.
- package/.jshintignore +18 -1
- package/.jshintrc +47 -47
- package/.npmignore +20 -17
- package/.travis.yml +11 -7
- package/LICENSE +23 -23
- package/README.md +137 -65
- package/lib/build/buildRegex.js +34 -18
- package/lib/build/tld.txt +11350 -8181
- package/lib/parseDomain.js +85 -67
- package/lib/tld.js +1 -1
- package/package.json +12 -23
- package/test/parseDomain.test.js +0 -107
package/.jshintignore
CHANGED
package/.jshintrc
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
{
|
|
2
|
-
"browser": false,
|
|
3
|
-
"node": true,
|
|
4
|
-
"expr": true,
|
|
5
|
-
"predef": [ // Extra globals.
|
|
6
|
-
"describe",
|
|
7
|
-
"it",
|
|
8
|
-
"before",
|
|
9
|
-
"after",
|
|
10
|
-
"beforeEach",
|
|
11
|
-
"afterEach"
|
|
12
|
-
],
|
|
13
|
-
|
|
14
|
-
"curly": true, // Require {} for every new block or scope.
|
|
15
|
-
"eqeqeq": true, // Require triple equals i.e. `===`.
|
|
16
|
-
"forin": true, // Tolerate `for in` loops without `hasOwnPrototype`.
|
|
17
|
-
"immed": true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
|
|
18
|
-
"latedef": false, // Prohibit variable use before definition.
|
|
19
|
-
"newcap": false, // Require capitalization of all constructor functions e.g. `new F()`.
|
|
20
|
-
"noempty": true, // Prohibit use of empty blocks.
|
|
21
|
-
"nonew": false, // Prohibit use of constructors for side-effects.
|
|
22
|
-
"plusplus": false, // Prohibit use of `++` & `--`.
|
|
23
|
-
"undef": true, // Require all non-global variables be declared before they are used.
|
|
24
|
-
"strict": true, // Require `use strict` pragma in every file.
|
|
25
|
-
"trailing": true, // Prohibit trailing whitespaces.
|
|
26
|
-
|
|
27
|
-
"asi": false, // Tolerate Automatic Semicolon Insertion (no semicolons).
|
|
28
|
-
"boss": false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
|
|
29
|
-
"debug": false, // Allow debugger statements e.g. browser breakpoints.
|
|
30
|
-
"eqnull": false, // Tolerate use of `== null`.
|
|
31
|
-
"esnext": false, // Allow ES.next specific features such as `const` and `let`.
|
|
32
|
-
"evil": false, // Tolerate use of `eval`.
|
|
33
|
-
"funcscope": false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
|
|
34
|
-
"globalstrict": false, // Allow global "use strict" (also enables 'strict').
|
|
35
|
-
"iterator": false, // Allow usage of __iterator__ property.
|
|
36
|
-
"lastsemic": false, // Tolerat missing semicolons when the it is omitted for the last statement in a one-line block.
|
|
37
|
-
"laxbreak": false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
|
|
38
|
-
"laxcomma": false, // Suppress warnings about comma-first coding style.
|
|
39
|
-
"loopfunc": false, // Allow functions to be defined within loops.
|
|
40
|
-
"multistr": false, // Tolerate multi-line strings.
|
|
41
|
-
"proto": false, // Tolerate __proto__ property. This property is deprecated.
|
|
42
|
-
"scripturl": false, // Tolerate script-targeted URLs.
|
|
43
|
-
"smarttabs": false, // Tolerate mixed tabs and spaces when the latter are used for alignmnent only.
|
|
44
|
-
"shadow": false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
|
|
45
|
-
"sub": true, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
|
|
46
|
-
"supernew": false, // Tolerate `new function () { ... };` and `new Object;`.
|
|
47
|
-
"validthis": false // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function
|
|
1
|
+
{
|
|
2
|
+
"browser": false,
|
|
3
|
+
"node": true,
|
|
4
|
+
"expr": true,
|
|
5
|
+
"predef": [ // Extra globals.
|
|
6
|
+
"describe",
|
|
7
|
+
"it",
|
|
8
|
+
"before",
|
|
9
|
+
"after",
|
|
10
|
+
"beforeEach",
|
|
11
|
+
"afterEach"
|
|
12
|
+
],
|
|
13
|
+
|
|
14
|
+
"curly": true, // Require {} for every new block or scope.
|
|
15
|
+
"eqeqeq": true, // Require triple equals i.e. `===`.
|
|
16
|
+
"forin": true, // Tolerate `for in` loops without `hasOwnPrototype`.
|
|
17
|
+
"immed": true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
|
|
18
|
+
"latedef": false, // Prohibit variable use before definition.
|
|
19
|
+
"newcap": false, // Require capitalization of all constructor functions e.g. `new F()`.
|
|
20
|
+
"noempty": true, // Prohibit use of empty blocks.
|
|
21
|
+
"nonew": false, // Prohibit use of constructors for side-effects.
|
|
22
|
+
"plusplus": false, // Prohibit use of `++` & `--`.
|
|
23
|
+
"undef": true, // Require all non-global variables be declared before they are used.
|
|
24
|
+
"strict": true, // Require `use strict` pragma in every file.
|
|
25
|
+
"trailing": true, // Prohibit trailing whitespaces.
|
|
26
|
+
|
|
27
|
+
"asi": false, // Tolerate Automatic Semicolon Insertion (no semicolons).
|
|
28
|
+
"boss": false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
|
|
29
|
+
"debug": false, // Allow debugger statements e.g. browser breakpoints.
|
|
30
|
+
"eqnull": false, // Tolerate use of `== null`.
|
|
31
|
+
"esnext": false, // Allow ES.next specific features such as `const` and `let`.
|
|
32
|
+
"evil": false, // Tolerate use of `eval`.
|
|
33
|
+
"funcscope": false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
|
|
34
|
+
"globalstrict": false, // Allow global "use strict" (also enables 'strict').
|
|
35
|
+
"iterator": false, // Allow usage of __iterator__ property.
|
|
36
|
+
"lastsemic": false, // Tolerat missing semicolons when the it is omitted for the last statement in a one-line block.
|
|
37
|
+
"laxbreak": false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
|
|
38
|
+
"laxcomma": false, // Suppress warnings about comma-first coding style.
|
|
39
|
+
"loopfunc": false, // Allow functions to be defined within loops.
|
|
40
|
+
"multistr": false, // Tolerate multi-line strings.
|
|
41
|
+
"proto": false, // Tolerate __proto__ property. This property is deprecated.
|
|
42
|
+
"scripturl": false, // Tolerate script-targeted URLs.
|
|
43
|
+
"smarttabs": false, // Tolerate mixed tabs and spaces when the latter are used for alignmnent only.
|
|
44
|
+
"shadow": false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
|
|
45
|
+
"sub": true, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
|
|
46
|
+
"supernew": false, // Tolerate `new function () { ... };` and `new Object;`.
|
|
47
|
+
"validthis": false // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function
|
|
48
48
|
}
|
package/.npmignore
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
lib-cov
|
|
2
|
-
*.seed
|
|
3
|
-
*.log
|
|
4
|
-
*.csv
|
|
5
|
-
*.dat
|
|
6
|
-
*.out
|
|
7
|
-
*.pid
|
|
8
|
-
*.gz
|
|
9
|
-
|
|
10
|
-
pids
|
|
11
|
-
logs
|
|
12
|
-
results
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
node_modules
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
lib-cov
|
|
2
|
+
*.seed
|
|
3
|
+
*.log
|
|
4
|
+
*.csv
|
|
5
|
+
*.dat
|
|
6
|
+
*.out
|
|
7
|
+
*.pid
|
|
8
|
+
*.gz
|
|
9
|
+
|
|
10
|
+
pids
|
|
11
|
+
logs
|
|
12
|
+
results
|
|
13
|
+
|
|
14
|
+
npm-debug.log
|
|
15
|
+
node_modules
|
|
16
|
+
coverage
|
|
17
|
+
examples
|
|
18
|
+
test
|
|
19
|
+
assets
|
|
20
|
+
.idea
|
package/.travis.yml
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
language: node_js
|
|
2
|
-
node_js:
|
|
3
|
-
- "0.10"
|
|
4
|
-
- "0.11"
|
|
5
|
-
|
|
6
|
-
script:
|
|
7
|
-
- npm test
|
|
1
|
+
language: node_js
|
|
2
|
+
node_js:
|
|
3
|
+
- "0.10"
|
|
4
|
+
- "0.11"
|
|
5
|
+
|
|
6
|
+
script:
|
|
7
|
+
- npm test
|
|
8
|
+
after_success:
|
|
9
|
+
- npm install -g istanbul
|
|
10
|
+
- npm install coveralls
|
|
11
|
+
- istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
|
package/LICENSE
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
This is free and unencumbered software released into the public domain.
|
|
2
|
-
|
|
3
|
-
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
-
distribute this software, either in source code form or as a compiled
|
|
5
|
-
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
-
means.
|
|
7
|
-
|
|
8
|
-
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
-
of this software dedicate any and all copyright interest in the
|
|
10
|
-
software to the public domain. We make this dedication for the benefit
|
|
11
|
-
of the public at large and to the detriment of our heirs and
|
|
12
|
-
successors. We intend this dedication to be an overt act of
|
|
13
|
-
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
-
software under copyright law.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
-
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
-
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
-
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
7
|
+
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and
|
|
12
|
+
successors. We intend this dedication to be an overt act of
|
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
+
software under copyright law.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
24
|
For more information, please refer to <http://unlicense.org>
|
package/README.md
CHANGED
|
@@ -1,65 +1,137 @@
|
|
|
1
|
-
parse-domain
|
|
2
|
-
|
|
3
|
-
**Splits
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
###
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
1
|
+
parse-domain
|
|
2
|
+
============
|
|
3
|
+
**Splits a URL into sub-domain, domain and the effective top-level domain.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/parse-domain)
|
|
6
|
+
[](https://www.npmjs.com/package/parse-domain)
|
|
7
|
+
[](https://david-dm.org/peerigon/parse-domain)
|
|
8
|
+
|
|
9
|
+
Since domains are handled differently across different countries and organizations, splitting a URL into sub-domain, domain and top-level-domain parts is not a simple regexp. **parse-domain** uses a [large list of effective tld names](http://publicsuffix.org/list/effective_tld_names.dat) from publicsuffix.org to recognize different parts of the domain.
|
|
10
|
+
|
|
11
|
+
Please also read the note on [effective top-level domains](#note-on-effective-top-level-domains).
|
|
12
|
+
|
|
13
|
+
<br />
|
|
14
|
+
|
|
15
|
+
Installation
|
|
16
|
+
------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install --save parse-domain
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
<br />
|
|
23
|
+
|
|
24
|
+
Usage
|
|
25
|
+
------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
// long subdomains can be handled
|
|
29
|
+
expect(parseDomain("some.subdomain.example.co.uk")).to.eql({
|
|
30
|
+
subdomain: "some.subdomain",
|
|
31
|
+
domain: "example",
|
|
32
|
+
tld: "co.uk"
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// usernames, passwords and ports are disregarded
|
|
36
|
+
expect(parseDomain("https://user:password@example.co.uk:8080/some/path?and&query#hash")).to.eql({
|
|
37
|
+
subdomain: "",
|
|
38
|
+
domain: "example",
|
|
39
|
+
tld: "co.uk"
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// non-canonical top-level domains are ignored
|
|
43
|
+
expect(parseDomain("unknown.tld.kk")).to.equal(null);
|
|
44
|
+
|
|
45
|
+
// invalid urls are also ignored
|
|
46
|
+
expect(parseDomain("invalid url")).to.equal(null);
|
|
47
|
+
expect(parseDomain({})).to.equal(null);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Introducing custom tlds
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
// custom top-level domains can optionally be specified
|
|
54
|
+
expect(parseDomain("mymachine.local",{ customTlds: ["local"] })).to.eql({
|
|
55
|
+
subdomain: "",
|
|
56
|
+
domain: "mymachine",
|
|
57
|
+
tld: "local"
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// custom regexps can optionally be specified (instead of customTlds)
|
|
61
|
+
expect(parseDomain("localhost",{ customTlds:/localhost|\.local/ })).to.eql({
|
|
62
|
+
subdomain: "",
|
|
63
|
+
domain: "",
|
|
64
|
+
tld: "localhost"
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
It can sometimes be helpful to apply the customTlds argument using a helper function
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
function parseLocalDomains(url) {
|
|
72
|
+
var options = {
|
|
73
|
+
customTlds: /localhost|\.local/
|
|
74
|
+
};
|
|
75
|
+
return parseDomain(url, options);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
expect(parseLocalDomains("localhost")).to.eql({
|
|
79
|
+
subdomain: "",
|
|
80
|
+
domain: "",
|
|
81
|
+
tld: "localhost"
|
|
82
|
+
});
|
|
83
|
+
expect(parseLocalDomains("mymachine.local")).to.eql({
|
|
84
|
+
subdomain: "",
|
|
85
|
+
domain: "mymachine",
|
|
86
|
+
tld: "local"
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
<br />
|
|
91
|
+
|
|
92
|
+
API
|
|
93
|
+
------------------------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
### `parseDomain(url: String, options: ParseOptions): ParsedDomain|null`
|
|
96
|
+
|
|
97
|
+
Returns `null` if `url` has an unknown tld or if it's not a valid url.
|
|
98
|
+
|
|
99
|
+
#### `ParseOptions`
|
|
100
|
+
```javascript
|
|
101
|
+
{
|
|
102
|
+
customTlds: RegExp|String[]
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### `ParsedDomain`
|
|
107
|
+
```javascript
|
|
108
|
+
{
|
|
109
|
+
tld: String,
|
|
110
|
+
domain: String,
|
|
111
|
+
subdomain: String
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
<br />
|
|
116
|
+
|
|
117
|
+
Note on effective top-level domains
|
|
118
|
+
------------------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
Technically, the top-level domain is *always* the part after the last dot. That's why publicsuffix.org is a list of *effective* top-level domains: It lists all top-level domains where users are allowed to host any content. That's why `foo.blogspot.com` will be split into
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
{
|
|
124
|
+
tld: "blogspot.com",
|
|
125
|
+
domain: "foo",
|
|
126
|
+
subdomain: ""
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
See also [#4](https://github.com/peerigon/parse-domain/issues/4)
|
|
131
|
+
|
|
132
|
+
<br />
|
|
133
|
+
|
|
134
|
+
License
|
|
135
|
+
------------------------------------------------------------------------
|
|
136
|
+
|
|
137
|
+
Unlicense
|
package/lib/build/buildRegex.js
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var fs = require("fs"),
|
|
4
|
-
path = require("path");
|
|
5
|
-
|
|
6
|
-
var tld,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var fs = require("fs"),
|
|
4
|
+
path = require("path");
|
|
5
|
+
|
|
6
|
+
var txtPath = path.resolve(__dirname, "./tld.txt"),
|
|
7
|
+
regexPath = path.resolve(__dirname, "../tld.js"),
|
|
8
|
+
tld,
|
|
9
|
+
src;
|
|
10
|
+
|
|
11
|
+
console.log("Reading " + txtPath + " ...");
|
|
12
|
+
|
|
13
|
+
tld = fs.readFileSync(txtPath, "utf8")
|
|
14
|
+
.replace(/(\/\/.+)\r?\n/gi, "")
|
|
15
|
+
.replace(/[\r?\n]+/g, "|")
|
|
16
|
+
.replace(/\./g, "\\.")
|
|
17
|
+
.replace(/\*/g, "[^.]+")
|
|
18
|
+
.slice(1, -1);
|
|
19
|
+
|
|
20
|
+
src = "module.exports = /\\.(" + tld + ")$/;";
|
|
21
|
+
|
|
22
|
+
console.log("Writing module at " + regexPath + " ...");
|
|
23
|
+
|
|
24
|
+
fs.writeFileSync(regexPath, src, "utf8");
|
|
25
|
+
|
|
26
|
+
console.log("Checking if it's valid JavaScript ...");
|
|
27
|
+
|
|
28
|
+
var regex = require(regexPath);
|
|
29
|
+
|
|
30
|
+
if (regex instanceof RegExp === false) {
|
|
31
|
+
throw new Error("Generated regex is not instanceof RegExp. Instead saw " + regex);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
console.log("Regex is ok, exiting now");
|