w3c-html-validator 1.6.4 → 1.7.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/README.md +6 -4
- package/bin/cli.js +4 -4
- package/dist/w3c-html-validator.d.ts +1 -1
- package/dist/w3c-html-validator.js +5 -6
- package/package.json +11 -17
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ _Check the markup validity of HTML files using the W3C validator_
|
|
|
8
8
|
[](https://github.com/center-key/w3c-html-validator/actions/workflows/run-spec-on-push.yaml)
|
|
9
9
|
|
|
10
10
|
**w3c-html-validator** takes HTML files and returns detailed validation results.
|
|
11
|
-
The reporter produces formatted output
|
|
11
|
+
The reporter produces formatted output indented for use in build scripts and test suites.
|
|
12
12
|
|
|
13
13
|
<img src=https://raw.githubusercontent.com/center-key/w3c-html-validator/main/examples.png
|
|
14
14
|
width=800 alt=screenshot>
|
|
@@ -20,7 +20,7 @@ $ npm install --save-dev w3c-html-validator
|
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## B) Usage
|
|
23
|
-
### 1. npm scripts
|
|
23
|
+
### 1. npm package.json scripts
|
|
24
24
|
Run `html-validator` from the `"scripts"` section of your **package.json** file.
|
|
25
25
|
|
|
26
26
|
The parameters are folders and files to be validated.
|
|
@@ -110,6 +110,8 @@ The dot (`.`) regex operator says to match any one character, which is a handy w
|
|
|
110
110
|
## D) Application Code and Testing Frameworks
|
|
111
111
|
In addition to the CLI interface, the **w3c-html-validator** package can also be imported and called directly in ESM and TypeScript projects.
|
|
112
112
|
|
|
113
|
+
Note that if your application calls `w3cHtmlValidator.validate()` multiple times, you must throttle (debounce) the calls or risk getting rejected by the W3C server.
|
|
114
|
+
|
|
113
115
|
### 1. Import
|
|
114
116
|
Example call to the `validate()` function:
|
|
115
117
|
```typescript
|
|
@@ -144,7 +146,7 @@ $ node examples.js
|
|
|
144
146
|
*The `ignoreMessages` and `ignoreLevel` options only work for `'json'` output.
|
|
145
147
|
Setting `ignoreLevel` to `'warning'` skips both `'warning'` level and `'info'` level validation messages.
|
|
146
148
|
|
|
147
|
-
#### w3cHtmlValidator.reporter(options)
|
|
149
|
+
#### w3cHtmlValidator.reporter(results, options)
|
|
148
150
|
| Name (key) | Type | Default | Description |
|
|
149
151
|
| :--------------- | :---------- | :------ | :-------------------------------------------------------------- |
|
|
150
152
|
| `continueOnFail` | **boolean** | `false` | Report messages but do not throw an error if validation failed. |
|
|
@@ -202,7 +204,7 @@ describe('Home page', () => {
|
|
|
202
204
|
- 🪺 [recursive-exec](https://github.com/center-key/recursive-exec): _Run a command on each file in a folder and its subfolders_
|
|
203
205
|
- 🔍 [replacer-util](https://github.com/center-key/replacer-util): _Find and replace strings or template outputs in text files_
|
|
204
206
|
- 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets): _Revision web asset filenames with cache busting content hash fingerprints_
|
|
205
|
-
- 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util): _Organize npm scripts into named groups of easy to manage commands_
|
|
207
|
+
- 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util): _Organize npm package.json scripts into named groups of easy to manage commands_
|
|
206
208
|
- 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator): _Check the markup validity of HTML files using the W3C validator_
|
|
207
209
|
|
|
208
210
|
Feel free to submit questions at:<br>
|
package/bin/cli.js
CHANGED
|
@@ -71,8 +71,8 @@ const getIgnoreMessages = () => {
|
|
|
71
71
|
const isRegex = /^\/.*\/$/; //starts and ends with a slash indicating it's a regex
|
|
72
72
|
return rawLines.map(line => isRegex.test(line) ? new RegExp(line.slice(1, -1)) : line);
|
|
73
73
|
};
|
|
74
|
-
const
|
|
75
|
-
const options =
|
|
76
|
-
const getReport =
|
|
77
|
-
const processFile =
|
|
74
|
+
const handleResults = (results) => w3cHtmlValidator.reporter(results, reporterOptions);
|
|
75
|
+
const options = (filename) => ({ filename: filename, ignoreMessages: getIgnoreMessages() });
|
|
76
|
+
const getReport = (filename) => w3cHtmlValidator.validate(options(filename)).then(handleResults);
|
|
77
|
+
const processFile = (filename, i) => globalThis.setTimeout(() => getReport(filename), i * delay);
|
|
78
78
|
filenames.forEach(processFile);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! w3c-html-validator v1.
|
|
1
|
+
//! w3c-html-validator v1.7.0 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import fs from 'fs';
|
|
@@ -6,7 +6,7 @@ import log from 'fancy-log';
|
|
|
6
6
|
import request from 'superagent';
|
|
7
7
|
import slash from 'slash';
|
|
8
8
|
const w3cHtmlValidator = {
|
|
9
|
-
version: '1.
|
|
9
|
+
version: '1.7.0',
|
|
10
10
|
validate(options) {
|
|
11
11
|
const defaults = {
|
|
12
12
|
checkUrl: 'https://validator.w3.org/nu/',
|
|
@@ -62,10 +62,9 @@ const w3cHtmlValidator = {
|
|
|
62
62
|
display: json ? null : response.text,
|
|
63
63
|
});
|
|
64
64
|
const handleError = (reason) => {
|
|
65
|
-
const
|
|
66
|
-
const getMsg = () => [
|
|
67
|
-
const message = response ? getMsg() : [reason.errno, reason.message];
|
|
68
|
-
const errRes = response ?? {};
|
|
65
|
+
const errRes = reason.response ?? {};
|
|
66
|
+
const getMsg = () => [errRes.status, errRes.res.statusMessage, errRes.request.url];
|
|
67
|
+
const message = reason.response ? getMsg() : [reason.errno, reason.message];
|
|
69
68
|
errRes.body = { messages: [{ type: 'network-error', message: message.join(' ') }] };
|
|
70
69
|
return toValidatorResults(errRes);
|
|
71
70
|
};
|
package/package.json
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w3c-html-validator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Check the markup validity of HTML files using the W3C validator",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"module": "dist/w3c-html-validator.js",
|
|
8
|
-
"main": "dist/w3c-html-validator.js",
|
|
9
8
|
"types": "dist/w3c-html-validator.d.ts",
|
|
9
|
+
"exports": "./dist/w3c-html-validator.js",
|
|
10
10
|
"files": [
|
|
11
11
|
"dist"
|
|
12
12
|
],
|
|
13
|
-
"exports": {
|
|
14
|
-
".": {
|
|
15
|
-
"import": "./dist/w3c-html-validator.js"
|
|
16
|
-
},
|
|
17
|
-
"./": "./dist/"
|
|
18
|
-
},
|
|
19
13
|
"bin": {
|
|
20
14
|
"html-validator": "bin/cli.js",
|
|
21
15
|
"w3c-html-validator": "bin/cli.js"
|
|
@@ -91,20 +85,20 @@
|
|
|
91
85
|
},
|
|
92
86
|
"devDependencies": {
|
|
93
87
|
"@types/fancy-log": "~2.0",
|
|
94
|
-
"@types/node": "~20.
|
|
88
|
+
"@types/node": "~20.11",
|
|
95
89
|
"@types/superagent": "~8.1",
|
|
96
|
-
"@typescript-eslint/eslint-plugin": "~
|
|
97
|
-
"@typescript-eslint/parser": "~
|
|
98
|
-
"add-dist-header": "~1.
|
|
99
|
-
"assert-deep-strict-equal": "~1.
|
|
100
|
-
"copy-file-util": "~1.
|
|
90
|
+
"@typescript-eslint/eslint-plugin": "~7.3",
|
|
91
|
+
"@typescript-eslint/parser": "~7.3",
|
|
92
|
+
"add-dist-header": "~1.4",
|
|
93
|
+
"assert-deep-strict-equal": "~1.2",
|
|
94
|
+
"copy-file-util": "~1.2",
|
|
101
95
|
"copy-folder-util": "~1.1",
|
|
102
|
-
"eslint": "~8.
|
|
96
|
+
"eslint": "~8.57",
|
|
103
97
|
"jshint": "~2.13",
|
|
104
98
|
"merge-stream": "~2.0",
|
|
105
|
-
"mocha": "~10.
|
|
99
|
+
"mocha": "~10.3",
|
|
106
100
|
"rimraf": "~5.0",
|
|
107
101
|
"run-scripts-util": "~1.2",
|
|
108
|
-
"typescript": "~5.
|
|
102
|
+
"typescript": "~5.4"
|
|
109
103
|
}
|
|
110
104
|
}
|