w3c-html-validator 0.8.1 → 1.0.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/LICENSE.txt +1 -1
- 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 +14 -7
- package/dist/w3c-html-validator.umd.cjs +14 -7
- package/package.json +12 -11
package/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2021 individual contributors to w3c-html-validator
|
|
3
|
+
Copyright (c) 2021-2022 individual contributors to w3c-html-validator
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
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
|
|
1
|
+
//! w3c-html-validator v1.0.2 ~~ 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
|
|
1
|
+
//! w3c-html-validator v1.0.2 ~~ 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: '0.
|
|
8
|
+
version: '1.0.2',
|
|
9
9
|
validate(options) {
|
|
10
10
|
const defaults = {
|
|
11
11
|
checkUrl: 'https://validator.w3.org/nu/',
|
|
@@ -15,11 +15,11 @@ const w3cHtmlValidator = {
|
|
|
15
15
|
};
|
|
16
16
|
const settings = { ...defaults, ...options };
|
|
17
17
|
if (!settings.html && !settings.filename && !settings.website)
|
|
18
|
-
throw Error('Must specify the "html", "filename", or "website" option.');
|
|
18
|
+
throw Error('[w3c-html-validator] Must specify the "html", "filename", or "website" option.');
|
|
19
19
|
if (![null, 'info', 'warning'].includes(settings.ignoreLevel))
|
|
20
20
|
throw Error('[w3c-html-validator] Invalid ignoreLevel option: ' + settings.ignoreLevel);
|
|
21
21
|
if (settings.output !== 'json' && settings.output !== 'html')
|
|
22
|
-
throw Error('Option "output" must be "json" or "html".');
|
|
22
|
+
throw Error('[w3c-html-validator] Option "output" must be "json" or "html".');
|
|
23
23
|
const mode = settings.html ? 'html' : settings.filename ? 'filename' : 'website';
|
|
24
24
|
const readFile = () => settings.filename ? readFileSync(settings.filename, 'utf8') : null;
|
|
25
25
|
const inputHtml = settings.html || readFile();
|
|
@@ -50,18 +50,25 @@ const w3cHtmlValidator = {
|
|
|
50
50
|
return response;
|
|
51
51
|
};
|
|
52
52
|
const toValidatorResults = (response) => ({
|
|
53
|
-
validates: json ? !response.body.messages.length : response.text
|
|
53
|
+
validates: json ? !response.body.messages.length : !!response.text?.includes(success),
|
|
54
54
|
mode: mode,
|
|
55
55
|
title: titleLookup[mode],
|
|
56
56
|
html: inputHtml,
|
|
57
57
|
filename: settings.filename || null,
|
|
58
58
|
website: settings.website || null,
|
|
59
59
|
output: settings.output,
|
|
60
|
-
status: response.statusCode,
|
|
60
|
+
status: response.statusCode || -1,
|
|
61
61
|
messages: json ? response.body.messages : null,
|
|
62
62
|
display: json ? null : response.text,
|
|
63
63
|
});
|
|
64
|
-
|
|
64
|
+
const handleError = (reason) => {
|
|
65
|
+
const response = reason['response'];
|
|
66
|
+
const getMsg = () => [response.status, response.res.statusMessage, response.request.url];
|
|
67
|
+
const message = response ? getMsg() : [reason['errno'], reason.message];
|
|
68
|
+
const networkErr = { type: 'network-error', message: message.join(' ') };
|
|
69
|
+
return toValidatorResults({ ...response, ...{ body: { messages: [networkErr] } } });
|
|
70
|
+
};
|
|
71
|
+
return w3cRequest.then(filterMessages).then(toValidatorResults).catch(handleError);
|
|
65
72
|
},
|
|
66
73
|
reporter(results, options) {
|
|
67
74
|
const defaults = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! w3c-html-validator
|
|
1
|
+
//! w3c-html-validator v1.0.2 ~~ 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: '0.
|
|
23
|
+
version: '1.0.2',
|
|
24
24
|
validate(options) {
|
|
25
25
|
const defaults = {
|
|
26
26
|
checkUrl: 'https://validator.w3.org/nu/',
|
|
@@ -30,11 +30,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
30
30
|
};
|
|
31
31
|
const settings = { ...defaults, ...options };
|
|
32
32
|
if (!settings.html && !settings.filename && !settings.website)
|
|
33
|
-
throw Error('Must specify the "html", "filename", or "website" option.');
|
|
33
|
+
throw Error('[w3c-html-validator] Must specify the "html", "filename", or "website" option.');
|
|
34
34
|
if (![null, 'info', 'warning'].includes(settings.ignoreLevel))
|
|
35
35
|
throw Error('[w3c-html-validator] Invalid ignoreLevel option: ' + settings.ignoreLevel);
|
|
36
36
|
if (settings.output !== 'json' && settings.output !== 'html')
|
|
37
|
-
throw Error('Option "output" must be "json" or "html".');
|
|
37
|
+
throw Error('[w3c-html-validator] Option "output" must be "json" or "html".');
|
|
38
38
|
const mode = settings.html ? 'html' : settings.filename ? 'filename' : 'website';
|
|
39
39
|
const readFile = () => settings.filename ? (0, fs_1.readFileSync)(settings.filename, 'utf8') : null;
|
|
40
40
|
const inputHtml = settings.html || readFile();
|
|
@@ -65,18 +65,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
65
65
|
return response;
|
|
66
66
|
};
|
|
67
67
|
const toValidatorResults = (response) => ({
|
|
68
|
-
validates: json ? !response.body.messages.length : response.text
|
|
68
|
+
validates: json ? !response.body.messages.length : !!response.text?.includes(success),
|
|
69
69
|
mode: mode,
|
|
70
70
|
title: titleLookup[mode],
|
|
71
71
|
html: inputHtml,
|
|
72
72
|
filename: settings.filename || null,
|
|
73
73
|
website: settings.website || null,
|
|
74
74
|
output: settings.output,
|
|
75
|
-
status: response.statusCode,
|
|
75
|
+
status: response.statusCode || -1,
|
|
76
76
|
messages: json ? response.body.messages : null,
|
|
77
77
|
display: json ? null : response.text,
|
|
78
78
|
});
|
|
79
|
-
|
|
79
|
+
const handleError = (reason) => {
|
|
80
|
+
const response = reason['response'];
|
|
81
|
+
const getMsg = () => [response.status, response.res.statusMessage, response.request.url];
|
|
82
|
+
const message = response ? getMsg() : [reason['errno'], reason.message];
|
|
83
|
+
const networkErr = { type: 'network-error', message: message.join(' ') };
|
|
84
|
+
return toValidatorResults({ ...response, ...{ body: { messages: [networkErr] } } });
|
|
85
|
+
};
|
|
86
|
+
return w3cRequest.then(filterMessages).then(toValidatorResults).catch(handleError);
|
|
80
87
|
},
|
|
81
88
|
reporter(results, options) {
|
|
82
89
|
const defaults = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w3c-html-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.2",
|
|
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",
|
|
@@ -73,26 +73,27 @@
|
|
|
73
73
|
"examples": "node examples.js"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"chalk": "~
|
|
77
|
-
"fancy-log": "~
|
|
76
|
+
"chalk": "~5.0",
|
|
77
|
+
"fancy-log": "~2.0",
|
|
78
78
|
"glob": "~7.2",
|
|
79
|
-
"superagent": "~
|
|
79
|
+
"superagent": "~7.1"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@types/fancy-log": "~1.3",
|
|
83
|
-
"@types/
|
|
83
|
+
"@types/glob": "~7.2",
|
|
84
|
+
"@types/node": "~17.0",
|
|
84
85
|
"@types/superagent": "~4.1",
|
|
85
|
-
"@typescript-eslint/eslint-plugin": "~
|
|
86
|
-
"@typescript-eslint/parser": "~
|
|
86
|
+
"@typescript-eslint/eslint-plugin": "~5.11",
|
|
87
|
+
"@typescript-eslint/parser": "~5.11",
|
|
87
88
|
"add-dist-header": "~0.1",
|
|
88
|
-
"assert-deep-strict-equal": "~
|
|
89
|
+
"assert-deep-strict-equal": "~1.0",
|
|
89
90
|
"cpy-cli": "~3.1",
|
|
90
|
-
"eslint": "~
|
|
91
|
+
"eslint": "~8.8",
|
|
91
92
|
"jshint": "~2.13",
|
|
92
93
|
"merge-stream": "~2.0",
|
|
93
|
-
"mocha": "~9.
|
|
94
|
+
"mocha": "~9.2",
|
|
94
95
|
"npm-run-all2": "~5.0",
|
|
95
96
|
"rimraf": "~3.0",
|
|
96
|
-
"typescript": "~4.
|
|
97
|
+
"typescript": "~4.5"
|
|
97
98
|
}
|
|
98
99
|
}
|