w3c-html-validator 1.0.0 → 1.0.3
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 +1 -1
- package/bin/cli.js +5 -2
- package/dist/w3c-html-validator.d.ts +2 -2
- package/dist/w3c-html-validator.js +42 -26
- package/dist/w3c-html-validator.umd.cjs +42 -26
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ _A package for testing HTML files or URLs against the W3C validator_
|
|
|
6
6
|
[](https://github.com/center-key/w3c-html-validator/blob/main/LICENSE.txt)
|
|
7
7
|
[](https://www.npmjs.com/package/w3c-html-validator)
|
|
8
8
|
[](https://snyk.io/test/github/center-key/w3c-html-validator)
|
|
9
|
-
[](https://github.com/center-key/w3c-html-validator/actions
|
|
9
|
+
[](https://github.com/center-key/w3c-html-validator/actions/workflows/run-spec-on-push.yaml)
|
|
10
10
|
|
|
11
11
|
## 1) Setup
|
|
12
12
|
|
package/bin/cli.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
//
|
|
2
|
+
////////////////////////
|
|
3
|
+
// w3c-html-validator //
|
|
4
|
+
// MIT License //
|
|
5
|
+
////////////////////////
|
|
6
|
+
|
|
4
7
|
// Usage in package.json:
|
|
5
8
|
// "scripts": {
|
|
6
9
|
// "validate": "w3c-html-validator docs/*.html flyer.html",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! w3c-html-validator v1.0.
|
|
1
|
+
//! w3c-html-validator v1.0.3 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
export declare type ValidatorOptions = {
|
|
4
4
|
html?: string;
|
|
@@ -10,7 +10,7 @@ export declare type ValidatorOptions = {
|
|
|
10
10
|
output?: ValidatorResultsOutput;
|
|
11
11
|
};
|
|
12
12
|
export declare type ValidatorResultsMessage = {
|
|
13
|
-
type: 'info' | 'error' | 'non-document-error';
|
|
13
|
+
type: 'info' | 'error' | 'non-document-error' | 'network-error';
|
|
14
14
|
subType?: 'warning' | 'fatal' | 'io' | 'schema' | 'internal';
|
|
15
15
|
message: string;
|
|
16
16
|
extract: string;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
//! w3c-html-validator v1.0.
|
|
1
|
+
//! w3c-html-validator v1.0.3 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
import { readFileSync } from 'fs';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import log from 'fancy-log';
|
|
6
6
|
import request from 'superagent';
|
|
7
7
|
const w3cHtmlValidator = {
|
|
8
|
-
version: '1.0.
|
|
8
|
+
version: '1.0.3',
|
|
9
9
|
validate(options) {
|
|
10
10
|
const defaults = {
|
|
11
11
|
checkUrl: 'https://validator.w3.org/nu/',
|
|
@@ -13,7 +13,7 @@ const w3cHtmlValidator = {
|
|
|
13
13
|
ignoreMessages: null,
|
|
14
14
|
output: 'json',
|
|
15
15
|
};
|
|
16
|
-
const settings = {
|
|
16
|
+
const settings = Object.assign(Object.assign({}, defaults), options);
|
|
17
17
|
if (!settings.html && !settings.filename && !settings.website)
|
|
18
18
|
throw Error('[w3c-html-validator] Must specify the "html", "filename", or "website" option.');
|
|
19
19
|
if (![null, 'info', 'warning'].includes(settings.ignoreLevel))
|
|
@@ -34,45 +34,60 @@ const w3cHtmlValidator = {
|
|
|
34
34
|
const json = settings.output === 'json';
|
|
35
35
|
const success = '<p class="success">';
|
|
36
36
|
const titleLookup = {
|
|
37
|
-
html: 'HTML String (characters: ' + inputHtml
|
|
37
|
+
html: 'HTML String (characters: ' + (inputHtml === null || inputHtml === void 0 ? void 0 : inputHtml.length) + ')',
|
|
38
38
|
filename: settings.filename,
|
|
39
39
|
website: settings.website,
|
|
40
40
|
};
|
|
41
41
|
const filterMessages = (response) => {
|
|
42
|
+
var _a, _b;
|
|
42
43
|
const aboveInfo = (subType) => settings.ignoreLevel === 'info' && !!subType;
|
|
43
44
|
const aboveIgnoreLevel = (message) => !settings.ignoreLevel || message.type !== 'info' || aboveInfo(message.subType);
|
|
44
45
|
const skipSubstr = (title) => typeof settings.ignoreMessages === 'string' && title.includes(settings.ignoreMessages);
|
|
45
|
-
const skipRegEx = (title) =>
|
|
46
|
-
|
|
46
|
+
const skipRegEx = (title) => {
|
|
47
|
+
var _a;
|
|
48
|
+
return ((_a = settings.ignoreMessages) === null || _a === void 0 ? void 0 : _a.constructor.name) === 'RegExp' &&
|
|
49
|
+
settings.ignoreMessages.test(title);
|
|
50
|
+
};
|
|
47
51
|
const isImportant = (message) => aboveIgnoreLevel(message) && !skipSubstr(message.message) && !skipRegEx(message.message);
|
|
48
52
|
if (json)
|
|
49
|
-
response.body.messages = response.body.messages
|
|
53
|
+
response.body.messages = (_b = (_a = response.body.messages) === null || _a === void 0 ? void 0 : _a.filter(isImportant)) !== null && _b !== void 0 ? _b : [];
|
|
50
54
|
return response;
|
|
51
55
|
};
|
|
52
|
-
const toValidatorResults = (response) =>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
const toValidatorResults = (response) => {
|
|
57
|
+
var _a;
|
|
58
|
+
return ({
|
|
59
|
+
validates: json ? !response.body.messages.length : !!((_a = response.text) === null || _a === void 0 ? void 0 : _a.includes(success)),
|
|
60
|
+
mode: mode,
|
|
61
|
+
title: titleLookup[mode],
|
|
62
|
+
html: inputHtml,
|
|
63
|
+
filename: settings.filename || null,
|
|
64
|
+
website: settings.website || null,
|
|
65
|
+
output: settings.output,
|
|
66
|
+
status: response.statusCode || -1,
|
|
67
|
+
messages: json ? response.body.messages : null,
|
|
68
|
+
display: json ? null : response.text,
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const handleError = (reason) => {
|
|
72
|
+
const response = reason['response'];
|
|
73
|
+
const getMsg = () => [response.status, response.res.statusMessage, response.request.url];
|
|
74
|
+
const message = response ? getMsg() : [reason['errno'], reason.message];
|
|
75
|
+
const networkErr = { type: 'network-error', message: message.join(' ') };
|
|
76
|
+
return toValidatorResults(Object.assign(Object.assign({}, response), { body: { messages: [networkErr] } }));
|
|
77
|
+
};
|
|
78
|
+
return w3cRequest.then(filterMessages).then(toValidatorResults).catch(handleError);
|
|
65
79
|
},
|
|
66
80
|
reporter(results, options) {
|
|
81
|
+
var _a, _b;
|
|
67
82
|
const defaults = {
|
|
68
83
|
maxMessageLen: null,
|
|
69
84
|
title: null,
|
|
70
85
|
};
|
|
71
|
-
const settings = {
|
|
72
|
-
if (typeof results
|
|
86
|
+
const settings = Object.assign(Object.assign({}, defaults), options);
|
|
87
|
+
if (typeof (results === null || results === void 0 ? void 0 : results.validates) !== 'boolean')
|
|
73
88
|
throw Error('[w3c-html-validator] Invalid results for reporter(): ' + String(results));
|
|
74
|
-
const messages = results.messages
|
|
75
|
-
const title = settings.title
|
|
89
|
+
const messages = (_a = results.messages) !== null && _a !== void 0 ? _a : [];
|
|
90
|
+
const title = (_b = settings.title) !== null && _b !== void 0 ? _b : results.title;
|
|
76
91
|
const fail = 'fail (messages: ' + messages.length + ')';
|
|
77
92
|
const status = results.validates ? chalk.green('pass') : chalk.red.bold(fail);
|
|
78
93
|
log(chalk.gray('w3c-html-validator'), chalk.blue.bold(title), status);
|
|
@@ -82,11 +97,12 @@ const w3cHtmlValidator = {
|
|
|
82
97
|
info: chalk.white.bold,
|
|
83
98
|
};
|
|
84
99
|
const logMessage = (message) => {
|
|
100
|
+
var _a, _b;
|
|
85
101
|
const type = message.subType || message.type;
|
|
86
102
|
const typeColor = typeColorMap[type] || chalk.redBright.bold;
|
|
87
103
|
const location = `line ${message.lastLine}, column ${message.firstColumn}:`;
|
|
88
|
-
const lineText = message.extract
|
|
89
|
-
const maxLen = settings.maxMessageLen
|
|
104
|
+
const lineText = (_a = message.extract) === null || _a === void 0 ? void 0 : _a.replace(/\n/g, '\\n');
|
|
105
|
+
const maxLen = (_b = settings.maxMessageLen) !== null && _b !== void 0 ? _b : undefined;
|
|
90
106
|
log(typeColor('HTML ' + type + ':'), message.message.substring(0, maxLen));
|
|
91
107
|
if (message.lastLine)
|
|
92
108
|
log(chalk.white(location), chalk.magenta(lineText));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! w3c-html-validator v1.0.
|
|
1
|
+
//! w3c-html-validator v1.0.3 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
const fancy_log_1 = __importDefault(require("fancy-log"));
|
|
21
21
|
const superagent_1 = __importDefault(require("superagent"));
|
|
22
22
|
const w3cHtmlValidator = {
|
|
23
|
-
version: '1.0.
|
|
23
|
+
version: '1.0.3',
|
|
24
24
|
validate(options) {
|
|
25
25
|
const defaults = {
|
|
26
26
|
checkUrl: 'https://validator.w3.org/nu/',
|
|
@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
ignoreMessages: null,
|
|
29
29
|
output: 'json',
|
|
30
30
|
};
|
|
31
|
-
const settings = {
|
|
31
|
+
const settings = Object.assign(Object.assign({}, defaults), options);
|
|
32
32
|
if (!settings.html && !settings.filename && !settings.website)
|
|
33
33
|
throw Error('[w3c-html-validator] Must specify the "html", "filename", or "website" option.');
|
|
34
34
|
if (![null, 'info', 'warning'].includes(settings.ignoreLevel))
|
|
@@ -49,45 +49,60 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
49
49
|
const json = settings.output === 'json';
|
|
50
50
|
const success = '<p class="success">';
|
|
51
51
|
const titleLookup = {
|
|
52
|
-
html: 'HTML String (characters: ' + inputHtml
|
|
52
|
+
html: 'HTML String (characters: ' + (inputHtml === null || inputHtml === void 0 ? void 0 : inputHtml.length) + ')',
|
|
53
53
|
filename: settings.filename,
|
|
54
54
|
website: settings.website,
|
|
55
55
|
};
|
|
56
56
|
const filterMessages = (response) => {
|
|
57
|
+
var _a, _b;
|
|
57
58
|
const aboveInfo = (subType) => settings.ignoreLevel === 'info' && !!subType;
|
|
58
59
|
const aboveIgnoreLevel = (message) => !settings.ignoreLevel || message.type !== 'info' || aboveInfo(message.subType);
|
|
59
60
|
const skipSubstr = (title) => typeof settings.ignoreMessages === 'string' && title.includes(settings.ignoreMessages);
|
|
60
|
-
const skipRegEx = (title) =>
|
|
61
|
-
|
|
61
|
+
const skipRegEx = (title) => {
|
|
62
|
+
var _a;
|
|
63
|
+
return ((_a = settings.ignoreMessages) === null || _a === void 0 ? void 0 : _a.constructor.name) === 'RegExp' &&
|
|
64
|
+
settings.ignoreMessages.test(title);
|
|
65
|
+
};
|
|
62
66
|
const isImportant = (message) => aboveIgnoreLevel(message) && !skipSubstr(message.message) && !skipRegEx(message.message);
|
|
63
67
|
if (json)
|
|
64
|
-
response.body.messages = response.body.messages
|
|
68
|
+
response.body.messages = (_b = (_a = response.body.messages) === null || _a === void 0 ? void 0 : _a.filter(isImportant)) !== null && _b !== void 0 ? _b : [];
|
|
65
69
|
return response;
|
|
66
70
|
};
|
|
67
|
-
const toValidatorResults = (response) =>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
const toValidatorResults = (response) => {
|
|
72
|
+
var _a;
|
|
73
|
+
return ({
|
|
74
|
+
validates: json ? !response.body.messages.length : !!((_a = response.text) === null || _a === void 0 ? void 0 : _a.includes(success)),
|
|
75
|
+
mode: mode,
|
|
76
|
+
title: titleLookup[mode],
|
|
77
|
+
html: inputHtml,
|
|
78
|
+
filename: settings.filename || null,
|
|
79
|
+
website: settings.website || null,
|
|
80
|
+
output: settings.output,
|
|
81
|
+
status: response.statusCode || -1,
|
|
82
|
+
messages: json ? response.body.messages : null,
|
|
83
|
+
display: json ? null : response.text,
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
const handleError = (reason) => {
|
|
87
|
+
const response = reason['response'];
|
|
88
|
+
const getMsg = () => [response.status, response.res.statusMessage, response.request.url];
|
|
89
|
+
const message = response ? getMsg() : [reason['errno'], reason.message];
|
|
90
|
+
const networkErr = { type: 'network-error', message: message.join(' ') };
|
|
91
|
+
return toValidatorResults(Object.assign(Object.assign({}, response), { body: { messages: [networkErr] } }));
|
|
92
|
+
};
|
|
93
|
+
return w3cRequest.then(filterMessages).then(toValidatorResults).catch(handleError);
|
|
80
94
|
},
|
|
81
95
|
reporter(results, options) {
|
|
96
|
+
var _a, _b;
|
|
82
97
|
const defaults = {
|
|
83
98
|
maxMessageLen: null,
|
|
84
99
|
title: null,
|
|
85
100
|
};
|
|
86
|
-
const settings = {
|
|
87
|
-
if (typeof results
|
|
101
|
+
const settings = Object.assign(Object.assign({}, defaults), options);
|
|
102
|
+
if (typeof (results === null || results === void 0 ? void 0 : results.validates) !== 'boolean')
|
|
88
103
|
throw Error('[w3c-html-validator] Invalid results for reporter(): ' + String(results));
|
|
89
|
-
const messages = results.messages
|
|
90
|
-
const title = settings.title
|
|
104
|
+
const messages = (_a = results.messages) !== null && _a !== void 0 ? _a : [];
|
|
105
|
+
const title = (_b = settings.title) !== null && _b !== void 0 ? _b : results.title;
|
|
91
106
|
const fail = 'fail (messages: ' + messages.length + ')';
|
|
92
107
|
const status = results.validates ? chalk_1.default.green('pass') : chalk_1.default.red.bold(fail);
|
|
93
108
|
(0, fancy_log_1.default)(chalk_1.default.gray('w3c-html-validator'), chalk_1.default.blue.bold(title), status);
|
|
@@ -97,11 +112,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
97
112
|
info: chalk_1.default.white.bold,
|
|
98
113
|
};
|
|
99
114
|
const logMessage = (message) => {
|
|
115
|
+
var _a, _b;
|
|
100
116
|
const type = message.subType || message.type;
|
|
101
117
|
const typeColor = typeColorMap[type] || chalk_1.default.redBright.bold;
|
|
102
118
|
const location = `line ${message.lastLine}, column ${message.firstColumn}:`;
|
|
103
|
-
const lineText = message.extract
|
|
104
|
-
const maxLen = settings.maxMessageLen
|
|
119
|
+
const lineText = (_a = message.extract) === null || _a === void 0 ? void 0 : _a.replace(/\n/g, '\\n');
|
|
120
|
+
const maxLen = (_b = settings.maxMessageLen) !== null && _b !== void 0 ? _b : undefined;
|
|
105
121
|
(0, fancy_log_1.default)(typeColor('HTML ' + type + ':'), message.message.substring(0, maxLen));
|
|
106
122
|
if (message.lastLine)
|
|
107
123
|
(0, fancy_log_1.default)(chalk_1.default.white(location), chalk_1.default.magenta(lineText));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w3c-html-validator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A package for testing HTML files or URLs against the W3C validator (written in TypeScript)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"step:03": "eslint --max-warnings 0 . --ext .ts",
|
|
67
67
|
"step:04": "tsc",
|
|
68
68
|
"step:05": "tsc --module UMD --outDir build/umd",
|
|
69
|
-
"step:06": "cpy build/umd/w3c-html-validator.js build --rename=w3c-html-validator.umd.cjs",
|
|
69
|
+
"step:06": "cpy build/umd/w3c-html-validator.js build --rename=w3c-html-validator.umd.cjs --flat=true",
|
|
70
70
|
"step:07": "add-dist-header build dist",
|
|
71
71
|
"pretest": "npm-run-all step:*",
|
|
72
72
|
"test": "mocha spec/*.spec.js --timeout 5000",
|
|
@@ -76,24 +76,24 @@
|
|
|
76
76
|
"chalk": "~5.0",
|
|
77
77
|
"fancy-log": "~2.0",
|
|
78
78
|
"glob": "~7.2",
|
|
79
|
-
"superagent": "~7.
|
|
79
|
+
"superagent": "~7.1"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@types/fancy-log": "~1.3",
|
|
83
83
|
"@types/glob": "~7.2",
|
|
84
84
|
"@types/node": "~17.0",
|
|
85
85
|
"@types/superagent": "~4.1",
|
|
86
|
-
"@typescript-eslint/eslint-plugin": "~5.
|
|
87
|
-
"@typescript-eslint/parser": "~5.
|
|
86
|
+
"@typescript-eslint/eslint-plugin": "~5.15",
|
|
87
|
+
"@typescript-eslint/parser": "~5.15",
|
|
88
88
|
"add-dist-header": "~0.1",
|
|
89
|
-
"assert-deep-strict-equal": "~
|
|
90
|
-
"cpy-cli": "~
|
|
91
|
-
"eslint": "~8.
|
|
89
|
+
"assert-deep-strict-equal": "~1.0",
|
|
90
|
+
"cpy-cli": "~4.1",
|
|
91
|
+
"eslint": "~8.11",
|
|
92
92
|
"jshint": "~2.13",
|
|
93
93
|
"merge-stream": "~2.0",
|
|
94
|
-
"mocha": "~9.
|
|
94
|
+
"mocha": "~9.2",
|
|
95
95
|
"npm-run-all2": "~5.0",
|
|
96
96
|
"rimraf": "~3.0",
|
|
97
|
-
"typescript": "~4.
|
|
97
|
+
"typescript": "~4.6"
|
|
98
98
|
}
|
|
99
99
|
}
|