robots-parser 2.3.0 → 2.4.0
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/index.d.ts +12 -0
- package/package.json +18 -7
- package/readme.md +74 -70
package/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare module 'robots-parser';
|
|
2
|
+
|
|
3
|
+
interface Robot {
|
|
4
|
+
isAllowed(url: string, ua?: string): boolean | undefined;
|
|
5
|
+
isDisallowed(url: string, ua?: string): boolean | undefined;
|
|
6
|
+
getMatchingLineNumber(url: string, ua?: string): number;
|
|
7
|
+
getCrawlDelay(ua?: string): number | undefined;
|
|
8
|
+
getSitemaps(): string[];
|
|
9
|
+
getPreferredHost(): string | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default function robotsParser(url: string, robotstxt: string): Robot;
|
package/package.json
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "robots-parser",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.4.0",
|
|
4
|
+
"description": "NodeJS robots.txt parser with support for wildcard (*) matching.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"robots.txt",
|
|
7
|
+
"parser",
|
|
8
|
+
"user-agent",
|
|
9
|
+
"scraper",
|
|
10
|
+
"spider",
|
|
11
|
+
"bot",
|
|
12
|
+
"robots-exclusion-standard"
|
|
13
|
+
],
|
|
5
14
|
"main": "index.js",
|
|
6
15
|
"directories": {
|
|
7
16
|
"test": "tests"
|
|
@@ -17,7 +26,8 @@
|
|
|
17
26
|
"license": "MIT",
|
|
18
27
|
"files": [
|
|
19
28
|
"/Robots.js",
|
|
20
|
-
"/index.js"
|
|
29
|
+
"/index.js",
|
|
30
|
+
"/index.d.ts"
|
|
21
31
|
],
|
|
22
32
|
"prettier": {
|
|
23
33
|
"tabWidth": 4,
|
|
@@ -26,8 +36,9 @@
|
|
|
26
36
|
"trailingComma": "none"
|
|
27
37
|
},
|
|
28
38
|
"devDependencies": {
|
|
29
|
-
"chai": "^4.
|
|
30
|
-
"mocha": "^
|
|
31
|
-
"nyc": "^
|
|
32
|
-
}
|
|
39
|
+
"chai": "^4.3.4",
|
|
40
|
+
"mocha": "^9.1.3",
|
|
41
|
+
"nyc": "^15.1.0"
|
|
42
|
+
},
|
|
43
|
+
"types": "./index.d.ts"
|
|
33
44
|
}
|
package/readme.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
# Robots Parser [](https://deepscan.io/dashboard#view=project&tid=457&pid=16277&bid=344939) [](https://github.com/samclarke/robots-parser/blob/master/license.md) [](https://coveralls.io/github/samclarke/robots-parser?branch=master)
|
|
1
|
+
# Robots Parser [](https://www.npmjs.com/package/robots-parser) [](https://deepscan.io/dashboard#view=project&tid=457&pid=16277&bid=344939) [](https://github.com/samclarke/robots-parser/blob/master/license.md) [](https://coveralls.io/github/samclarke/robots-parser?branch=master)
|
|
2
2
|
|
|
3
3
|
NodeJS robots.txt parser.
|
|
4
4
|
|
|
5
5
|
It currently supports:
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
- User-agent:
|
|
8
|
+
- Allow:
|
|
9
|
+
- Disallow:
|
|
10
|
+
- Sitemap:
|
|
11
|
+
- Crawl-delay:
|
|
12
|
+
- Host:
|
|
13
|
+
- Paths with wildcards (\*) and EOL matching ($)
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -38,7 +38,7 @@ var robots = robotsParser('http://www.example.com/robots.txt', [
|
|
|
38
38
|
'Host: example.com'
|
|
39
39
|
].join('\n'));
|
|
40
40
|
|
|
41
|
-
robots.isAllowed('http://www.example.com/test.html', 'Sams-Bot/1.0'); //
|
|
41
|
+
robots.isAllowed('http://www.example.com/test.html', 'Sams-Bot/1.0'); // true
|
|
42
42
|
robots.isAllowed('http://www.example.com/dir/test.html', 'Sams-Bot/1.0'); // true
|
|
43
43
|
robots.isDisallowed('http://www.example.com/dir/test2.html', 'Sams-Bot/1.0'); // true
|
|
44
44
|
robots.getCrawlDelay('Sams-Bot/1.0'); // 1
|
|
@@ -46,24 +46,24 @@ robots.getSitemaps(); // ['http://example.com/sitemap.xml']
|
|
|
46
46
|
robots.getPreferredHost(); // example.com
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
|
|
50
49
|
### isAllowed(url, [ua])
|
|
50
|
+
|
|
51
51
|
**boolean or undefined**
|
|
52
52
|
|
|
53
53
|
Returns true if crawling the specified URL is allowed for the specified user-agent.
|
|
54
54
|
|
|
55
55
|
This will return `undefined` if the URL isn't valid for this robots.txt.
|
|
56
56
|
|
|
57
|
-
|
|
58
57
|
### isDisallowed(url, [ua])
|
|
58
|
+
|
|
59
59
|
**boolean or undefined**
|
|
60
60
|
|
|
61
61
|
Returns true if crawling the specified URL is not allowed for the specified user-agent.
|
|
62
62
|
|
|
63
63
|
This will return `undefined` if the URL isn't valid for this robots.txt.
|
|
64
64
|
|
|
65
|
-
|
|
66
65
|
### getMatchingLineNumber(url, [ua])
|
|
66
|
+
|
|
67
67
|
**number or undefined**
|
|
68
68
|
|
|
69
69
|
Returns the line number of the matching directive for the specified URL and user-agent if any.
|
|
@@ -72,115 +72,119 @@ Line numbers start at 1 and go up (1-based indexing).
|
|
|
72
72
|
|
|
73
73
|
Returns -1 if there is no matching directive. If a rule is manually added without a lineNumber then this will return undefined for that rule.
|
|
74
74
|
|
|
75
|
-
|
|
76
75
|
### getCrawlDelay([ua])
|
|
76
|
+
|
|
77
77
|
**number or undefined**
|
|
78
78
|
|
|
79
79
|
Returns the number of seconds the specified user-agent should wait between requests.
|
|
80
80
|
|
|
81
81
|
Returns undefined if no crawl delay has been specified for this user-agent.
|
|
82
82
|
|
|
83
|
-
|
|
84
83
|
### getSitemaps()
|
|
84
|
+
|
|
85
85
|
**array**
|
|
86
86
|
|
|
87
87
|
Returns an array of sitemap URLs specified by the `sitemap:` directive.
|
|
88
88
|
|
|
89
|
-
|
|
90
89
|
### getPreferredHost()
|
|
90
|
+
|
|
91
91
|
**string or null**
|
|
92
92
|
|
|
93
93
|
Returns the preferred host name specified by the `host:` directive or null if there isn't one.
|
|
94
94
|
|
|
95
|
-
|
|
96
95
|
# Changes
|
|
97
96
|
|
|
97
|
+
### Version 2.4.0:
|
|
98
|
+
|
|
99
|
+
- Added Typescript definitions
|
|
100
|
+
– Thanks to @danhab99 for creating
|
|
101
|
+
- Added SECURITY.md policy and CodeQL scanning
|
|
102
|
+
|
|
98
103
|
### Version 2.3.0:
|
|
99
104
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
Relative matching is only allowed if both the robots.txt URL and the URLs being checked are relative.
|
|
105
|
+
- Fixed bug where if the user-agent passed to `isAllowed()` / `isDisallowed()` is called "constructor" it would throw an error.
|
|
106
|
+
- Added support for relative URLs. This does not affect the default behavior so can safely be upgraded.
|
|
104
107
|
|
|
105
|
-
|
|
106
|
-
```js
|
|
107
|
-
var robots = robotsParser('/robots.txt', [
|
|
108
|
-
'User-agent: *',
|
|
109
|
-
'Disallow: /dir/',
|
|
110
|
-
'Disallow: /test.html',
|
|
111
|
-
'Allow: /dir/test.html',
|
|
112
|
-
'Allow: /test.html'
|
|
113
|
-
].join('\n'));
|
|
108
|
+
Relative matching is only allowed if both the robots.txt URL and the URLs being checked are relative.
|
|
114
109
|
|
|
115
|
-
|
|
116
|
-
robots.isAllowed('/dir/test.html', 'Sams-Bot/1.0'); // true
|
|
117
|
-
robots.isDisallowed('/dir/test2.html', 'Sams-Bot/1.0'); // true
|
|
118
|
-
```
|
|
110
|
+
For example:
|
|
119
111
|
|
|
112
|
+
```js
|
|
113
|
+
var robots = robotsParser('/robots.txt', [
|
|
114
|
+
'User-agent: *',
|
|
115
|
+
'Disallow: /dir/',
|
|
116
|
+
'Disallow: /test.html',
|
|
117
|
+
'Allow: /dir/test.html',
|
|
118
|
+
'Allow: /test.html'
|
|
119
|
+
].join('\n'));
|
|
120
|
+
|
|
121
|
+
robots.isAllowed('/test.html', 'Sams-Bot/1.0'); // false
|
|
122
|
+
robots.isAllowed('/dir/test.html', 'Sams-Bot/1.0'); // true
|
|
123
|
+
robots.isDisallowed('/dir/test2.html', 'Sams-Bot/1.0'); // true
|
|
124
|
+
```
|
|
120
125
|
|
|
121
126
|
### Version 2.2.0:
|
|
122
127
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
- Fixed bug that with matching wildcard patterns with some URLs
|
|
129
|
+
– Thanks to @ckylape for reporting and fixing
|
|
130
|
+
- Changed matching algorithm to match Google's implementation in google/robotstxt
|
|
131
|
+
- Changed order of precedence to match current spec
|
|
127
132
|
|
|
128
133
|
### Version 2.1.1:
|
|
129
134
|
|
|
130
|
-
|
|
131
|
-
|
|
135
|
+
- Fix bug that could be used to causing rule checking to take a long time
|
|
136
|
+
– Thanks to @andeanfog
|
|
132
137
|
|
|
133
138
|
### Version 2.1.0:
|
|
134
139
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
- Removed use of punycode module API's as new URL API handles it
|
|
141
|
+
- Improved test coverage
|
|
142
|
+
- Added tests for percent encoded paths and improved support
|
|
143
|
+
- Added `getMatchingLineNumber()` method
|
|
144
|
+
- Fixed bug with comments on same line as directive
|
|
140
145
|
|
|
141
146
|
### Version 2.0.0:
|
|
142
147
|
|
|
143
148
|
This release is not 100% backwards compatible as it now uses the new URL APIs which are not supported in Node < 7.
|
|
144
149
|
|
|
145
|
-
|
|
146
|
-
|
|
150
|
+
- Update code to not use deprecated URL module API's.
|
|
151
|
+
– Thanks to @kdzwinel
|
|
147
152
|
|
|
148
153
|
### Version 1.0.2:
|
|
149
154
|
|
|
150
|
-
|
|
155
|
+
- Fixed error caused by invalid URLs missing the protocol.
|
|
151
156
|
|
|
152
157
|
### Version 1.0.1:
|
|
153
158
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
159
|
+
- Fixed bug with the "user-agent" rule being treated as case sensitive.
|
|
160
|
+
– Thanks to @brendonboshell
|
|
161
|
+
- Improved test coverage.
|
|
162
|
+
– Thanks to @schornio
|
|
158
163
|
|
|
159
164
|
### Version 1.0.0:
|
|
160
165
|
|
|
161
|
-
|
|
162
|
-
|
|
166
|
+
- Initial release.
|
|
163
167
|
|
|
164
168
|
# License
|
|
165
169
|
|
|
166
|
-
|
|
170
|
+
The MIT License (MIT)
|
|
167
171
|
|
|
168
|
-
|
|
172
|
+
Copyright (c) 2014 Sam Clarke
|
|
169
173
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
175
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
176
|
+
in the Software without restriction, including without limitation the rights
|
|
177
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
178
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
179
|
+
furnished to do so, subject to the following conditions:
|
|
176
180
|
|
|
177
|
-
|
|
178
|
-
|
|
181
|
+
The above copyright notice and this permission notice shall be included in
|
|
182
|
+
all copies or substantial portions of the Software.
|
|
179
183
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
184
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
185
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
186
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
187
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
188
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
189
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
190
|
+
THE SOFTWARE.
|