w3c-html-validator 1.3.3 → 1.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/bin/cli.js +2 -2
- package/dist/w3c-html-validator.d.ts +1 -1
- package/dist/w3c-html-validator.js +4 -4
- package/package.json +15 -16
- package/dist/w3c-html-validator.umd.cjs +0 -141
package/bin/cli.js
CHANGED
|
@@ -32,8 +32,8 @@ const validFlags = ['continue', 'delay', 'exclude', 'ignore', 'note', 'quiet', '
|
|
|
32
32
|
const cli = cliArgvUtil.parse(validFlags);
|
|
33
33
|
const files = cli.params;
|
|
34
34
|
const ignore = cli.flagMap.ignore ?? null;
|
|
35
|
-
const delay =
|
|
36
|
-
const trim =
|
|
35
|
+
const delay = Number(cli.flagMap.delay) || 500; //default half second debounce pause
|
|
36
|
+
const trim = Number(cli.flagMap.trim) || null;
|
|
37
37
|
|
|
38
38
|
// Validator
|
|
39
39
|
const keep = (filename) => !filename.includes('node_modules/');
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
//! w3c-html-validator v1.
|
|
1
|
+
//! w3c-html-validator v1.4.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';
|
|
5
5
|
import log from 'fancy-log';
|
|
6
6
|
import request from 'superagent';
|
|
7
7
|
const w3cHtmlValidator = {
|
|
8
|
-
version: '1.
|
|
8
|
+
version: '1.4.0',
|
|
9
9
|
validate(options) {
|
|
10
10
|
var _a;
|
|
11
11
|
const defaults = {
|
|
@@ -70,9 +70,9 @@ const w3cHtmlValidator = {
|
|
|
70
70
|
});
|
|
71
71
|
};
|
|
72
72
|
const handleError = (reason) => {
|
|
73
|
-
const response = reason
|
|
73
|
+
const response = reason.response;
|
|
74
74
|
const getMsg = () => [response.status, response.res.statusMessage, response.request.url];
|
|
75
|
-
const message = response ? getMsg() : [reason
|
|
75
|
+
const message = response ? getMsg() : [reason.errno, reason.message];
|
|
76
76
|
const networkErr = { type: 'network-error', message: message.join(' ') };
|
|
77
77
|
return toValidatorResults(Object.assign(Object.assign({}, response), { body: { messages: [networkErr] } }));
|
|
78
78
|
};
|
package/package.json
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w3c-html-validator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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.
|
|
8
|
+
"main": "dist/w3c-html-validator.js",
|
|
9
9
|
"types": "dist/w3c-html-validator.d.ts",
|
|
10
10
|
"files": [
|
|
11
11
|
"dist"
|
|
12
12
|
],
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
|
-
"import": "./dist/w3c-html-validator.js"
|
|
16
|
-
"require": "./dist/w3c-html-validator.umd.cjs"
|
|
15
|
+
"import": "./dist/w3c-html-validator.js"
|
|
17
16
|
},
|
|
18
17
|
"./": "./dist/"
|
|
19
18
|
},
|
|
@@ -62,18 +61,18 @@
|
|
|
62
61
|
}
|
|
63
62
|
},
|
|
64
63
|
"runScriptsConfig": {
|
|
64
|
+
"clean": [
|
|
65
|
+
"rimraf build dist"
|
|
66
|
+
],
|
|
65
67
|
"build": [
|
|
66
|
-
"rimraf build dist",
|
|
67
68
|
"jshint . --exclude-path .gitignore",
|
|
68
69
|
"eslint --max-warnings 0 . --ext .ts",
|
|
69
70
|
"tsc",
|
|
70
|
-
"tsc --module UMD --outDir build/umd",
|
|
71
|
-
"copy-file build/umd/w3c-html-validator.js build/w3c-html-validator.umd.cjs",
|
|
72
71
|
"add-dist-header build dist"
|
|
73
72
|
]
|
|
74
73
|
},
|
|
75
74
|
"scripts": {
|
|
76
|
-
"pretest": "run-scripts build",
|
|
75
|
+
"pretest": "run-scripts clean build",
|
|
77
76
|
"test": "mocha spec/*.spec.js --timeout 5000",
|
|
78
77
|
"examples": "node examples.js"
|
|
79
78
|
},
|
|
@@ -81,26 +80,26 @@
|
|
|
81
80
|
"chalk": "~5.2",
|
|
82
81
|
"cli-argv-util": "~1.0",
|
|
83
82
|
"fancy-log": "~2.0",
|
|
84
|
-
"glob": "~
|
|
83
|
+
"glob": "~10.2",
|
|
85
84
|
"superagent": "~8.0"
|
|
86
85
|
},
|
|
87
86
|
"devDependencies": {
|
|
88
87
|
"@types/fancy-log": "~2.0",
|
|
89
88
|
"@types/glob": "~8.1",
|
|
90
|
-
"@types/node": "~
|
|
89
|
+
"@types/node": "~20.3",
|
|
91
90
|
"@types/superagent": "~4.1",
|
|
92
|
-
"@typescript-eslint/eslint-plugin": "~5.
|
|
93
|
-
"@typescript-eslint/parser": "~5.
|
|
91
|
+
"@typescript-eslint/eslint-plugin": "~5.60",
|
|
92
|
+
"@typescript-eslint/parser": "~5.60",
|
|
94
93
|
"add-dist-header": "~1.0",
|
|
95
94
|
"assert-deep-strict-equal": "~1.0",
|
|
96
95
|
"copy-file-util": "~1.0",
|
|
97
96
|
"copy-folder-util": "~1.0",
|
|
98
|
-
"eslint": "~8.
|
|
97
|
+
"eslint": "~8.43",
|
|
99
98
|
"jshint": "~2.13",
|
|
100
99
|
"merge-stream": "~2.0",
|
|
101
100
|
"mocha": "~10.2",
|
|
102
|
-
"rimraf": "~
|
|
103
|
-
"run-scripts-util": "~1.
|
|
104
|
-
"typescript": "~5.
|
|
101
|
+
"rimraf": "~5.0",
|
|
102
|
+
"run-scripts-util": "~1.1",
|
|
103
|
+
"typescript": "~5.1"
|
|
105
104
|
}
|
|
106
105
|
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
//! w3c-html-validator v1.3.3 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
|
-
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
(function (factory) {
|
|
7
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
8
|
-
var v = factory(require, exports);
|
|
9
|
-
if (v !== undefined) module.exports = v;
|
|
10
|
-
}
|
|
11
|
-
else if (typeof define === "function" && define.amd) {
|
|
12
|
-
define(["require", "exports", "chalk", "fs", "fancy-log", "superagent"], factory);
|
|
13
|
-
}
|
|
14
|
-
})(function (require, exports) {
|
|
15
|
-
"use strict";
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.w3cHtmlValidator = void 0;
|
|
18
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
19
|
-
const fs_1 = __importDefault(require("fs"));
|
|
20
|
-
const fancy_log_1 = __importDefault(require("fancy-log"));
|
|
21
|
-
const superagent_1 = __importDefault(require("superagent"));
|
|
22
|
-
const w3cHtmlValidator = {
|
|
23
|
-
version: '1.3.3',
|
|
24
|
-
validate(options) {
|
|
25
|
-
var _a;
|
|
26
|
-
const defaults = {
|
|
27
|
-
checkUrl: 'https://validator.w3.org/nu/',
|
|
28
|
-
ignoreLevel: null,
|
|
29
|
-
ignoreMessages: null,
|
|
30
|
-
output: 'json',
|
|
31
|
-
};
|
|
32
|
-
const settings = Object.assign(Object.assign({}, defaults), options);
|
|
33
|
-
if (!settings.html && !settings.filename && !settings.website)
|
|
34
|
-
throw Error('[w3c-html-validator] Must specify the "html", "filename", or "website" option.');
|
|
35
|
-
if (![null, 'info', 'warning'].includes(settings.ignoreLevel))
|
|
36
|
-
throw Error('[w3c-html-validator] Invalid ignoreLevel option: ' + settings.ignoreLevel);
|
|
37
|
-
if (settings.output !== 'json' && settings.output !== 'html')
|
|
38
|
-
throw Error('[w3c-html-validator] Option "output" must be "json" or "html".');
|
|
39
|
-
const mode = settings.html ? 'html' : settings.filename ? 'filename' : 'website';
|
|
40
|
-
const readFile = (filename) => fs_1.default.readFileSync(filename, 'utf-8').replace(/\r/g, '');
|
|
41
|
-
const inputHtml = (_a = settings.html) !== null && _a !== void 0 ? _a : (settings.filename ? readFile(settings.filename) : null);
|
|
42
|
-
const makePostRequest = () => superagent_1.default.post(settings.checkUrl)
|
|
43
|
-
.set('Content-Type', 'text/html; encoding=utf-8')
|
|
44
|
-
.send(inputHtml);
|
|
45
|
-
const makeGetRequest = () => superagent_1.default.get(settings.checkUrl)
|
|
46
|
-
.query({ doc: settings.website });
|
|
47
|
-
const w3cRequest = inputHtml ? makePostRequest() : makeGetRequest();
|
|
48
|
-
w3cRequest.set('User-Agent', 'W3C HTML Validator ~ github.com/center-key/w3c-html-validator');
|
|
49
|
-
w3cRequest.query({ out: settings.output });
|
|
50
|
-
const json = settings.output === 'json';
|
|
51
|
-
const success = '<p class="success">';
|
|
52
|
-
const titleLookup = {
|
|
53
|
-
html: 'HTML String (characters: ' + (inputHtml === null || inputHtml === void 0 ? void 0 : inputHtml.length) + ')',
|
|
54
|
-
filename: settings.filename,
|
|
55
|
-
website: settings.website,
|
|
56
|
-
};
|
|
57
|
-
const filterMessages = (response) => {
|
|
58
|
-
var _a, _b;
|
|
59
|
-
const aboveInfo = (subType) => settings.ignoreLevel === 'info' && !!subType;
|
|
60
|
-
const aboveIgnoreLevel = (message) => !settings.ignoreLevel || message.type !== 'info' || aboveInfo(message.subType);
|
|
61
|
-
const skipSubstr = (title) => typeof settings.ignoreMessages === 'string' && title.includes(settings.ignoreMessages);
|
|
62
|
-
const skipRegEx = (title) => {
|
|
63
|
-
var _a;
|
|
64
|
-
return ((_a = settings.ignoreMessages) === null || _a === void 0 ? void 0 : _a.constructor.name) === 'RegExp' &&
|
|
65
|
-
settings.ignoreMessages.test(title);
|
|
66
|
-
};
|
|
67
|
-
const isImportant = (message) => aboveIgnoreLevel(message) && !skipSubstr(message.message) && !skipRegEx(message.message);
|
|
68
|
-
if (json)
|
|
69
|
-
response.body.messages = (_b = (_a = response.body.messages) === null || _a === void 0 ? void 0 : _a.filter(isImportant)) !== null && _b !== void 0 ? _b : [];
|
|
70
|
-
return response;
|
|
71
|
-
};
|
|
72
|
-
const toValidatorResults = (response) => {
|
|
73
|
-
var _a;
|
|
74
|
-
return ({
|
|
75
|
-
validates: json ? !response.body.messages.length : !!((_a = response.text) === null || _a === void 0 ? void 0 : _a.includes(success)),
|
|
76
|
-
mode: mode,
|
|
77
|
-
title: titleLookup[mode],
|
|
78
|
-
html: inputHtml,
|
|
79
|
-
filename: settings.filename || null,
|
|
80
|
-
website: settings.website || null,
|
|
81
|
-
output: settings.output,
|
|
82
|
-
status: response.statusCode || -1,
|
|
83
|
-
messages: json ? response.body.messages : null,
|
|
84
|
-
display: json ? null : response.text,
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
const handleError = (reason) => {
|
|
88
|
-
const response = reason['response'];
|
|
89
|
-
const getMsg = () => [response.status, response.res.statusMessage, response.request.url];
|
|
90
|
-
const message = response ? getMsg() : [reason['errno'], reason.message];
|
|
91
|
-
const networkErr = { type: 'network-error', message: message.join(' ') };
|
|
92
|
-
return toValidatorResults(Object.assign(Object.assign({}, response), { body: { messages: [networkErr] } }));
|
|
93
|
-
};
|
|
94
|
-
return w3cRequest.then(filterMessages).then(toValidatorResults).catch(handleError);
|
|
95
|
-
},
|
|
96
|
-
reporter(results, options) {
|
|
97
|
-
var _a, _b;
|
|
98
|
-
const defaults = {
|
|
99
|
-
continueOnFail: false,
|
|
100
|
-
maxMessageLen: null,
|
|
101
|
-
quiet: false,
|
|
102
|
-
title: null,
|
|
103
|
-
};
|
|
104
|
-
const settings = Object.assign(Object.assign({}, defaults), options);
|
|
105
|
-
if (typeof (results === null || results === void 0 ? void 0 : results.validates) !== 'boolean')
|
|
106
|
-
throw Error('[w3c-html-validator] Invalid results for reporter(): ' + String(results));
|
|
107
|
-
const messages = (_a = results.messages) !== null && _a !== void 0 ? _a : [];
|
|
108
|
-
const title = (_b = settings.title) !== null && _b !== void 0 ? _b : results.title;
|
|
109
|
-
const status = results.validates ? chalk_1.default.green.bold('✔ pass') : chalk_1.default.red.bold('✘ fail');
|
|
110
|
-
const count = results.validates ? '' : '(messages: ' + messages.length + ')';
|
|
111
|
-
if (!results.validates || !settings.quiet)
|
|
112
|
-
(0, fancy_log_1.default)(chalk_1.default.gray('w3c-html-validator'), status, chalk_1.default.blue.bold(title), chalk_1.default.white(count));
|
|
113
|
-
const typeColorMap = {
|
|
114
|
-
error: chalk_1.default.red.bold,
|
|
115
|
-
warning: chalk_1.default.yellow.bold,
|
|
116
|
-
info: chalk_1.default.white.bold,
|
|
117
|
-
};
|
|
118
|
-
const logMessage = (message) => {
|
|
119
|
-
var _a, _b, _c, _d;
|
|
120
|
-
const type = ((_a = message.subType) !== null && _a !== void 0 ? _a : message.type);
|
|
121
|
-
const typeColor = (_b = typeColorMap[type]) !== null && _b !== void 0 ? _b : chalk_1.default.redBright.bold;
|
|
122
|
-
const location = `line ${message.lastLine}, column ${message.firstColumn}:`;
|
|
123
|
-
const lineText = (_c = message.extract) === null || _c === void 0 ? void 0 : _c.replace(/\n/g, '\\n');
|
|
124
|
-
const maxLen = (_d = settings.maxMessageLen) !== null && _d !== void 0 ? _d : undefined;
|
|
125
|
-
(0, fancy_log_1.default)(typeColor('HTML ' + type + ':'), message.message.substring(0, maxLen));
|
|
126
|
-
if (message.lastLine)
|
|
127
|
-
(0, fancy_log_1.default)(chalk_1.default.white(location), chalk_1.default.magenta(lineText));
|
|
128
|
-
};
|
|
129
|
-
messages.forEach(logMessage);
|
|
130
|
-
const failDetails = () => {
|
|
131
|
-
const toString = (message) => { var _a; return `${(_a = message.subType) !== null && _a !== void 0 ? _a : message.type} line ${message.lastLine} column ${message.firstColumn}`; };
|
|
132
|
-
const fileDetails = () => results.filename + ' -- ' + results.messages.map(toString).join(', ');
|
|
133
|
-
return !results.filename ? results.messages[0].message : fileDetails();
|
|
134
|
-
};
|
|
135
|
-
if (!settings.continueOnFail && !results.validates)
|
|
136
|
-
throw Error('[w3c-html-validator] Failed: ' + failDetails());
|
|
137
|
-
return results;
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
exports.w3cHtmlValidator = w3cHtmlValidator;
|
|
141
|
-
});
|