w3c-html-validator 1.1.0 → 1.1.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/README.md +23 -14
- package/bin/cli.js +29 -16
- package/dist/w3c-html-validator.d.ts +2 -1
- package/dist/w3c-html-validator.js +8 -5
- package/dist/w3c-html-validator.umd.cjs +8 -5
- package/package.json +14 -12
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# W3C HTML Validator
|
|
2
2
|
<img src=https://centerkey.com/graphics/center-key-logo.svg align=right width=200 alt=logo>
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
_Check the markup validity of HTML files using the W3C validator_
|
|
5
5
|
|
|
6
6
|
[](https://github.com/center-key/w3c-html-validator/blob/main/LICENSE.txt)
|
|
7
7
|
[](https://www.npmjs.com/package/w3c-html-validator)
|
|
@@ -57,10 +57,11 @@ width=800 alt=screenshot>
|
|
|
57
57
|
Option value `'warning'` also skips `'info'`.
|
|
58
58
|
|
|
59
59
|
### w3cHtmlValidator.reporter(options)
|
|
60
|
-
| Name (key) | Type
|
|
61
|
-
| :-------------- |
|
|
62
|
-
| `maxMessageLen` | **number**
|
|
63
|
-
| `
|
|
60
|
+
| Name (key) | Type | Default | Description |
|
|
61
|
+
| :-------------- | :---------- | :------ | :------------------------------------------------------------- |
|
|
62
|
+
| `maxMessageLen` | **number** | `null` | Trim validation messages to not exceed a maximum length. |
|
|
63
|
+
| `quiet` | **boolean** | `false` | Suppress messages for successful validations. |
|
|
64
|
+
| `title` | **string** | `null` | Override display title (useful for naming HTML string inputs). |
|
|
64
65
|
|
|
65
66
|
## 4) TypeScript Declarations
|
|
66
67
|
The **TypeScript Declaration File** file is [w3c-html-validator.d.ts](dist/w3c-html-validator.d.ts)
|
|
@@ -101,27 +102,35 @@ describe('Home page', () => {
|
|
|
101
102
|
```
|
|
102
103
|
|
|
103
104
|
## 6) Command Line
|
|
104
|
-
|
|
105
|
+
You can install **w3c-html-validator** globally and then run it anywhere directly from the terminal.
|
|
106
|
+
|
|
107
|
+
Example terminal commands:
|
|
105
108
|
```shell
|
|
106
|
-
$ npm install --
|
|
107
|
-
$
|
|
108
|
-
$
|
|
109
|
-
$
|
|
109
|
+
$ npm install --global w3c-html-validator
|
|
110
|
+
$ html-validator docs/*.html flyer.html
|
|
111
|
+
$ html-validator docs #validate html files in a folder
|
|
112
|
+
$ html-validator #validate all html files in project
|
|
110
113
|
```
|
|
111
114
|
or as an npm script in **package.json**:
|
|
112
115
|
```json
|
|
113
116
|
"scripts": {
|
|
114
|
-
"validate":
|
|
115
|
-
"folder":
|
|
116
|
-
"all":
|
|
117
|
+
"validate": "html-validator docs/*.html flyer.html",
|
|
118
|
+
"one-folder": "html-validator docs",
|
|
119
|
+
"all": "html-validator"
|
|
117
120
|
},
|
|
118
121
|
```
|
|
119
|
-
Passing no parameters defaults to validating all HTML files in the
|
|
122
|
+
Passing no parameters defaults to validating all HTML files in the project (skipping the
|
|
120
123
|
**node_modules** folder).
|
|
121
124
|
|
|
122
125
|
<br>
|
|
123
126
|
|
|
124
127
|
---
|
|
128
|
+
**Build Tools**
|
|
129
|
+
- 🎋 [add-dist-header](https://github.com/center-key/add-dist-header): _Prepend a one-line header comment (with license notice) to distribution files_
|
|
130
|
+
- 📄 [copy-file-util](https://github.com/center-key/copy-file-util): _Copy or rename a file (CLI tool designed for use in npm scripts)_
|
|
131
|
+
- 📂 [copy-folder-cli](https://github.com/center-key/copy-folder-cli): _Recursively copy a folder (CLI tool designed for use in npm scripts)_
|
|
132
|
+
- 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator): _Check the markup validity of HTML files using the W3C validator_
|
|
133
|
+
|
|
125
134
|
Feel free to submit questions at:<br>
|
|
126
135
|
[github.com/center-key/w3c-html-validator/issues](https://github.com/center-key/w3c-html-validator/issues)
|
|
127
136
|
|
package/bin/cli.js
CHANGED
|
@@ -6,40 +6,53 @@
|
|
|
6
6
|
|
|
7
7
|
// Usage in package.json:
|
|
8
8
|
// "scripts": {
|
|
9
|
-
// "validate": "
|
|
10
|
-
// "all": "
|
|
9
|
+
// "validate": "html-validator docs/*.html flyer.html",
|
|
10
|
+
// "all": "html-validator"
|
|
11
11
|
// },
|
|
12
12
|
//
|
|
13
13
|
// Usage from command line:
|
|
14
|
-
// $
|
|
15
|
-
// $
|
|
14
|
+
// $ npm install --global w3c-html-validator
|
|
15
|
+
// $ html-validator docs/*.html flyer.html
|
|
16
|
+
// $ html-validator #validate all html files in the project
|
|
16
17
|
//
|
|
17
18
|
// Contributors to this project:
|
|
18
19
|
// $ cd w3c-html-validator
|
|
19
|
-
// $ node bin/cli.js spec/**/*.html
|
|
20
|
+
// $ node bin/cli.js spec/**/*.html --quiet
|
|
20
21
|
|
|
21
22
|
// Imports
|
|
23
|
+
import { w3cHtmlValidator } from '../dist/w3c-html-validator.js';
|
|
24
|
+
import { lstatSync } from 'fs';
|
|
22
25
|
import chalk from 'chalk';
|
|
23
26
|
import glob from 'glob';
|
|
24
27
|
import log from 'fancy-log';
|
|
25
|
-
import { lstatSync } from 'fs';
|
|
26
|
-
import { w3cHtmlValidator } from '../dist/w3c-html-validator.js';
|
|
27
28
|
|
|
28
29
|
// Parameters
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
30
|
+
const validFlags = ['quiet'];
|
|
31
|
+
const args = process.argv.slice(2);
|
|
32
|
+
const flags = args.filter(arg => /^--/.test(arg));
|
|
33
|
+
const flagMap = Object.fromEntries(flags.map(flag => flag.replace(/^--/, '').split('=')));
|
|
34
|
+
const invalidFlag = Object.keys(flagMap).find(key => !validFlags.includes(key));
|
|
35
|
+
const params = args.filter(arg => !/^--/.test(arg));
|
|
36
|
+
|
|
37
|
+
// Data
|
|
38
|
+
const files = params;
|
|
39
|
+
const mode = { quiet: 'quiet' in flagMap };
|
|
32
40
|
|
|
33
41
|
// Validator
|
|
34
|
-
const exit = (message) => (console.error('[w3c-html-validator] ' + message), process.exit(1));
|
|
35
|
-
if (flags.length)
|
|
36
|
-
exit('Flags not supported: ' + flags.join(' '));
|
|
37
42
|
const keep = (filename) => !filename.includes('node_modules/');
|
|
38
43
|
const readFolder = (folder) => glob.sync(folder + '**/*.html', { ignore: '**/node_modules/**/*' });
|
|
39
44
|
const expandFolder = (file) => lstatSync(file).isDirectory() ? readFolder(file + '/') : file;
|
|
40
45
|
const getFilenames = () => [...new Set(files.map(expandFolder).flat().filter(keep))].sort();
|
|
41
46
|
const filenames = files.length ? getFilenames() : readFolder('');
|
|
42
|
-
|
|
47
|
+
const error =
|
|
48
|
+
invalidFlag ? 'Invalid flag: ' + invalidFlag :
|
|
49
|
+
!files.length ? 'Missing file parameter.' :
|
|
50
|
+
!filenames.length ? 'No files to validate.' :
|
|
51
|
+
null;
|
|
52
|
+
if (error)
|
|
53
|
+
throw Error('[w3c-html-validator] ' + error);
|
|
54
|
+
if (filenames.length > 1 && !mode.quiet)
|
|
43
55
|
log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + filenames.length));
|
|
44
|
-
|
|
45
|
-
|
|
56
|
+
const reporterOptions = { quiet: mode.quiet };
|
|
57
|
+
const handleReport = (report) => w3cHtmlValidator.reporter(report, reporterOptions);
|
|
58
|
+
filenames.forEach(file => w3cHtmlValidator.validate({ filename: file }).then(handleReport));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! w3c-html-validator v1.1.
|
|
1
|
+
//! w3c-html-validator v1.1.2 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
export declare type ValidatorOptions = {
|
|
4
4
|
html?: string;
|
|
@@ -37,6 +37,7 @@ export declare type ValidatorResults = {
|
|
|
37
37
|
export declare type ValidatorResultsOutput = ValidatorResults['output'];
|
|
38
38
|
export declare type ReporterOptions = {
|
|
39
39
|
maxMessageLen?: number | null;
|
|
40
|
+
quiet?: boolean;
|
|
40
41
|
title?: string | null;
|
|
41
42
|
};
|
|
42
43
|
declare const w3cHtmlValidator: {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
//! w3c-html-validator v1.1.
|
|
1
|
+
//! w3c-html-validator v1.1.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: '1.1.
|
|
8
|
+
version: '1.1.2',
|
|
9
9
|
validate(options) {
|
|
10
|
+
var _a;
|
|
10
11
|
const defaults = {
|
|
11
12
|
checkUrl: 'https://validator.w3.org/nu/',
|
|
12
13
|
ignoreLevel: null,
|
|
@@ -21,8 +22,8 @@ const w3cHtmlValidator = {
|
|
|
21
22
|
if (settings.output !== 'json' && settings.output !== 'html')
|
|
22
23
|
throw Error('[w3c-html-validator] Option "output" must be "json" or "html".');
|
|
23
24
|
const mode = settings.html ? 'html' : settings.filename ? 'filename' : 'website';
|
|
24
|
-
const readFile = () =>
|
|
25
|
-
const inputHtml = settings.html
|
|
25
|
+
const readFile = (filename) => readFileSync(filename, 'utf8').replace(/\r/g, '');
|
|
26
|
+
const inputHtml = (_a = settings.html) !== null && _a !== void 0 ? _a : (settings.filename ? readFile(settings.filename) : null);
|
|
26
27
|
const makePostRequest = () => request.post(settings.checkUrl)
|
|
27
28
|
.set('Content-Type', 'text/html; encoding=utf-8')
|
|
28
29
|
.send(inputHtml);
|
|
@@ -81,6 +82,7 @@ const w3cHtmlValidator = {
|
|
|
81
82
|
var _a, _b;
|
|
82
83
|
const defaults = {
|
|
83
84
|
maxMessageLen: null,
|
|
85
|
+
quiet: false,
|
|
84
86
|
title: null,
|
|
85
87
|
};
|
|
86
88
|
const settings = Object.assign(Object.assign({}, defaults), options);
|
|
@@ -90,7 +92,8 @@ const w3cHtmlValidator = {
|
|
|
90
92
|
const title = (_b = settings.title) !== null && _b !== void 0 ? _b : results.title;
|
|
91
93
|
const status = results.validates ? chalk.green.bold('✔ pass') : chalk.red.bold('✘ fail');
|
|
92
94
|
const count = results.validates ? '' : '(messages: ' + messages.length + ')';
|
|
93
|
-
|
|
95
|
+
if (!results.validates || !settings.quiet)
|
|
96
|
+
log(chalk.gray('w3c-html-validator'), status, chalk.blue.bold(title), chalk.white(count));
|
|
94
97
|
const typeColorMap = {
|
|
95
98
|
error: chalk.red.bold,
|
|
96
99
|
warning: chalk.yellow.bold,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! w3c-html-validator v1.1.
|
|
1
|
+
//! w3c-html-validator v1.1.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,8 +20,9 @@ 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.1.
|
|
23
|
+
version: '1.1.2',
|
|
24
24
|
validate(options) {
|
|
25
|
+
var _a;
|
|
25
26
|
const defaults = {
|
|
26
27
|
checkUrl: 'https://validator.w3.org/nu/',
|
|
27
28
|
ignoreLevel: null,
|
|
@@ -36,8 +37,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
37
|
if (settings.output !== 'json' && settings.output !== 'html')
|
|
37
38
|
throw Error('[w3c-html-validator] Option "output" must be "json" or "html".');
|
|
38
39
|
const mode = settings.html ? 'html' : settings.filename ? 'filename' : 'website';
|
|
39
|
-
const readFile = () =>
|
|
40
|
-
const inputHtml = settings.html
|
|
40
|
+
const readFile = (filename) => (0, fs_1.readFileSync)(filename, 'utf8').replace(/\r/g, '');
|
|
41
|
+
const inputHtml = (_a = settings.html) !== null && _a !== void 0 ? _a : (settings.filename ? readFile(settings.filename) : null);
|
|
41
42
|
const makePostRequest = () => superagent_1.default.post(settings.checkUrl)
|
|
42
43
|
.set('Content-Type', 'text/html; encoding=utf-8')
|
|
43
44
|
.send(inputHtml);
|
|
@@ -96,6 +97,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
96
97
|
var _a, _b;
|
|
97
98
|
const defaults = {
|
|
98
99
|
maxMessageLen: null,
|
|
100
|
+
quiet: false,
|
|
99
101
|
title: null,
|
|
100
102
|
};
|
|
101
103
|
const settings = Object.assign(Object.assign({}, defaults), options);
|
|
@@ -105,7 +107,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
105
107
|
const title = (_b = settings.title) !== null && _b !== void 0 ? _b : results.title;
|
|
106
108
|
const status = results.validates ? chalk_1.default.green.bold('✔ pass') : chalk_1.default.red.bold('✘ fail');
|
|
107
109
|
const count = results.validates ? '' : '(messages: ' + messages.length + ')';
|
|
108
|
-
|
|
110
|
+
if (!results.validates || !settings.quiet)
|
|
111
|
+
(0, fancy_log_1.default)(chalk_1.default.gray('w3c-html-validator'), status, chalk_1.default.blue.bold(title), chalk_1.default.white(count));
|
|
109
112
|
const typeColorMap = {
|
|
110
113
|
error: chalk_1.default.red.bold,
|
|
111
114
|
warning: chalk_1.default.yellow.bold,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w3c-html-validator",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.2",
|
|
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",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"./": "./dist/"
|
|
19
19
|
},
|
|
20
20
|
"bin": {
|
|
21
|
+
"html-validator": "bin/cli.js",
|
|
21
22
|
"w3c-html-validator": "bin/cli.js"
|
|
22
23
|
},
|
|
23
24
|
"repository": "github:center-key/w3c-html-validator",
|
|
@@ -62,11 +63,11 @@
|
|
|
62
63
|
},
|
|
63
64
|
"scripts": {
|
|
64
65
|
"step:01": "rimraf build dist **/.DS_Store",
|
|
65
|
-
"step:02": "jshint . --exclude
|
|
66
|
+
"step:02": "jshint . --exclude-path .gitignore",
|
|
66
67
|
"step:03": "eslint --max-warnings 0 . --ext .ts",
|
|
67
68
|
"step:04": "tsc",
|
|
68
69
|
"step:05": "tsc --module UMD --outDir build/umd",
|
|
69
|
-
"step:06": "
|
|
70
|
+
"step:06": "copy-file build/umd/w3c-html-validator.js build/w3c-html-validator.umd.cjs",
|
|
70
71
|
"step:07": "add-dist-header build dist",
|
|
71
72
|
"pretest": "npm-run-all step:*",
|
|
72
73
|
"test": "mocha spec/*.spec.js --timeout 5000",
|
|
@@ -80,20 +81,21 @@
|
|
|
80
81
|
},
|
|
81
82
|
"devDependencies": {
|
|
82
83
|
"@types/fancy-log": "~2.0",
|
|
83
|
-
"@types/glob": "~
|
|
84
|
-
"@types/node": "~18.
|
|
84
|
+
"@types/glob": "~8.0",
|
|
85
|
+
"@types/node": "~18.7",
|
|
85
86
|
"@types/superagent": "~4.1",
|
|
86
|
-
"@typescript-eslint/eslint-plugin": "~5.
|
|
87
|
-
"@typescript-eslint/parser": "~5.
|
|
88
|
-
"add-dist-header": "~0.
|
|
87
|
+
"@typescript-eslint/eslint-plugin": "~5.38",
|
|
88
|
+
"@typescript-eslint/parser": "~5.38",
|
|
89
|
+
"add-dist-header": "~0.2",
|
|
89
90
|
"assert-deep-strict-equal": "~1.0",
|
|
90
|
-
"
|
|
91
|
-
"
|
|
91
|
+
"copy-file-util": "~0.1",
|
|
92
|
+
"copy-folder-cli": "~0.1",
|
|
93
|
+
"eslint": "~8.23",
|
|
92
94
|
"jshint": "~2.13",
|
|
93
95
|
"merge-stream": "~2.0",
|
|
94
96
|
"mocha": "~10.0",
|
|
95
97
|
"npm-run-all2": "~6.0",
|
|
96
98
|
"rimraf": "~3.0",
|
|
97
|
-
"typescript": "~4.
|
|
99
|
+
"typescript": "~4.8"
|
|
98
100
|
}
|
|
99
101
|
}
|