w3c-html-validator 1.1.1 → 1.1.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 +31 -20
- package/bin/cli.js +33 -16
- package/dist/w3c-html-validator.d.ts +2 -1
- package/dist/w3c-html-validator.js +5 -3
- package/dist/w3c-html-validator.umd.cjs +5 -3
- package/package.json +9 -7
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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)
|
|
8
8
|
[](https://snyk.io/test/github/center-key/w3c-html-validator)
|
|
9
9
|
[](https://github.com/center-key/w3c-html-validator/actions/workflows/run-spec-on-push.yaml)
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## A) Setup
|
|
12
12
|
|
|
13
13
|
### Install
|
|
14
14
|
Install package for node:
|
|
@@ -23,7 +23,7 @@ import { w3cHtmlValidator } from 'w3c-html-validator';
|
|
|
23
23
|
```
|
|
24
24
|
or invoke directly [from the command line or from a **package.json** script](#6-command-line).
|
|
25
25
|
|
|
26
|
-
##
|
|
26
|
+
## B) Usage
|
|
27
27
|
Call the `validate()` function:
|
|
28
28
|
```javascript
|
|
29
29
|
const options = { filename: 'docs/index.html' };
|
|
@@ -41,7 +41,7 @@ $ node examples.js
|
|
|
41
41
|
<img src=https://raw.githubusercontent.com/center-key/w3c-html-validator/main/examples.png
|
|
42
42
|
width=800 alt=screenshot>
|
|
43
43
|
|
|
44
|
-
##
|
|
44
|
+
## C) Options
|
|
45
45
|
### w3cHtmlValidator.validate(options)
|
|
46
46
|
| Name (key) | Type | Default | Description |
|
|
47
47
|
| :--------------- | :---------------------- | :------------------------------- | :------------------------------------------------------------------- |
|
|
@@ -57,12 +57,13 @@ 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
|
+
## D) TypeScript Declarations
|
|
66
67
|
The **TypeScript Declaration File** file is [w3c-html-validator.d.ts](dist/w3c-html-validator.d.ts)
|
|
67
68
|
in the **dist** folder.
|
|
68
69
|
|
|
@@ -82,7 +83,7 @@ type ValidatorResults = {
|
|
|
82
83
|
};
|
|
83
84
|
```
|
|
84
85
|
|
|
85
|
-
##
|
|
86
|
+
## E) Mocha Example
|
|
86
87
|
```javascript
|
|
87
88
|
import assert from 'assert';
|
|
88
89
|
import { w3cHtmlValidator } from 'w3c-html-validator';
|
|
@@ -100,28 +101,38 @@ describe('Home page', () => {
|
|
|
100
101
|
});
|
|
101
102
|
```
|
|
102
103
|
|
|
103
|
-
##
|
|
104
|
-
|
|
104
|
+
## F) Command Line
|
|
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 #validate all html files in project
|
|
111
|
+
$ html-validator docs #validate html files in a folder
|
|
112
|
+
$ html-validator docs/*.html flyer.html
|
|
113
|
+
$ html-validator docs --quiet #suppress "pass" messages
|
|
114
|
+
$ html-validator docs --trim=30 #truncate messages to 30 characters
|
|
110
115
|
```
|
|
111
116
|
or as an npm script in **package.json**:
|
|
112
117
|
```json
|
|
113
118
|
"scripts": {
|
|
114
|
-
"validate":
|
|
115
|
-
"folder":
|
|
116
|
-
"all":
|
|
119
|
+
"validate": "html-validator docs/*.html flyer.html",
|
|
120
|
+
"one-folder": "html-validator docs",
|
|
121
|
+
"all": "html-validator --quiet"
|
|
117
122
|
},
|
|
118
123
|
```
|
|
119
|
-
Passing no parameters defaults to validating all HTML files in the
|
|
124
|
+
Passing no parameters defaults to validating all HTML files in the project (skipping the
|
|
120
125
|
**node_modules** folder).
|
|
121
126
|
|
|
122
127
|
<br>
|
|
123
128
|
|
|
124
129
|
---
|
|
130
|
+
**Build Tools**
|
|
131
|
+
- 🎋 [add-dist-header](https://github.com/center-key/add-dist-header): _Prepend a one-line header comment (with license notice) to distribution files_
|
|
132
|
+
- 📄 [copy-file-util](https://github.com/center-key/copy-file-util): _Copy or rename a file (CLI tool designed for use in npm scripts)_
|
|
133
|
+
- 📂 [copy-folder-cli](https://github.com/center-key/copy-folder-cli): _Recursively copy a folder (CLI tool designed for use in npm scripts)_
|
|
134
|
+
- 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator): _Check the markup validity of HTML files using the W3C validator_
|
|
135
|
+
|
|
125
136
|
Feel free to submit questions at:<br>
|
|
126
137
|
[github.com/center-key/w3c-html-validator/issues](https://github.com/center-key/w3c-html-validator/issues)
|
|
127
138
|
|
package/bin/cli.js
CHANGED
|
@@ -6,40 +6,57 @@
|
|
|
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', 'trim'];
|
|
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, trim: 'trim' in flagMap };
|
|
40
|
+
const trim = parseInt(flagMap.trim) || null;
|
|
32
41
|
|
|
33
42
|
// 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
43
|
const keep = (filename) => !filename.includes('node_modules/');
|
|
38
44
|
const readFolder = (folder) => glob.sync(folder + '**/*.html', { ignore: '**/node_modules/**/*' });
|
|
39
45
|
const expandFolder = (file) => lstatSync(file).isDirectory() ? readFolder(file + '/') : file;
|
|
40
46
|
const getFilenames = () => [...new Set(files.map(expandFolder).flat().filter(keep))].sort();
|
|
41
47
|
const filenames = files.length ? getFilenames() : readFolder('');
|
|
42
|
-
|
|
48
|
+
const error =
|
|
49
|
+
invalidFlag ? 'Invalid flag: ' + invalidFlag :
|
|
50
|
+
!filenames.length ? 'No files to validate.' :
|
|
51
|
+
mode.trim && !trim ? 'Value of "trim" must be a positive whole number.' :
|
|
52
|
+
null;
|
|
53
|
+
if (error)
|
|
54
|
+
throw Error('[w3c-html-validator] ' + error);
|
|
55
|
+
if (filenames.length > 1 && !mode.quiet)
|
|
43
56
|
log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + filenames.length));
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
const reporterOptions = {
|
|
58
|
+
quiet: mode.quiet,
|
|
59
|
+
maxMessageLen: trim,
|
|
60
|
+
};
|
|
61
|
+
const handleReport = (report) => w3cHtmlValidator.reporter(report, reporterOptions);
|
|
62
|
+
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.3 ~~ 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,11 +1,11 @@
|
|
|
1
|
-
//! w3c-html-validator v1.1.
|
|
1
|
+
//! w3c-html-validator v1.1.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.1.
|
|
8
|
+
version: '1.1.3',
|
|
9
9
|
validate(options) {
|
|
10
10
|
var _a;
|
|
11
11
|
const defaults = {
|
|
@@ -82,6 +82,7 @@ const w3cHtmlValidator = {
|
|
|
82
82
|
var _a, _b;
|
|
83
83
|
const defaults = {
|
|
84
84
|
maxMessageLen: null,
|
|
85
|
+
quiet: false,
|
|
85
86
|
title: null,
|
|
86
87
|
};
|
|
87
88
|
const settings = Object.assign(Object.assign({}, defaults), options);
|
|
@@ -91,7 +92,8 @@ const w3cHtmlValidator = {
|
|
|
91
92
|
const title = (_b = settings.title) !== null && _b !== void 0 ? _b : results.title;
|
|
92
93
|
const status = results.validates ? chalk.green.bold('✔ pass') : chalk.red.bold('✘ fail');
|
|
93
94
|
const count = results.validates ? '' : '(messages: ' + messages.length + ')';
|
|
94
|
-
|
|
95
|
+
if (!results.validates || !settings.quiet)
|
|
96
|
+
log(chalk.gray('w3c-html-validator'), status, chalk.blue.bold(title), chalk.white(count));
|
|
95
97
|
const typeColorMap = {
|
|
96
98
|
error: chalk.red.bold,
|
|
97
99
|
warning: chalk.yellow.bold,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! w3c-html-validator v1.1.
|
|
1
|
+
//! w3c-html-validator v1.1.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.1.
|
|
23
|
+
version: '1.1.3',
|
|
24
24
|
validate(options) {
|
|
25
25
|
var _a;
|
|
26
26
|
const defaults = {
|
|
@@ -97,6 +97,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
97
97
|
var _a, _b;
|
|
98
98
|
const defaults = {
|
|
99
99
|
maxMessageLen: null,
|
|
100
|
+
quiet: false,
|
|
100
101
|
title: null,
|
|
101
102
|
};
|
|
102
103
|
const settings = Object.assign(Object.assign({}, defaults), options);
|
|
@@ -106,7 +107,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
106
107
|
const title = (_b = settings.title) !== null && _b !== void 0 ? _b : results.title;
|
|
107
108
|
const status = results.validates ? chalk_1.default.green.bold('✔ pass') : chalk_1.default.red.bold('✘ fail');
|
|
108
109
|
const count = results.validates ? '' : '(messages: ' + messages.length + ')';
|
|
109
|
-
|
|
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));
|
|
110
112
|
const typeColorMap = {
|
|
111
113
|
error: chalk_1.default.red.bold,
|
|
112
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.3",
|
|
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",
|
|
@@ -83,11 +84,12 @@
|
|
|
83
84
|
"@types/glob": "~8.0",
|
|
84
85
|
"@types/node": "~18.7",
|
|
85
86
|
"@types/superagent": "~4.1",
|
|
86
|
-
"@typescript-eslint/eslint-plugin": "~5.
|
|
87
|
-
"@typescript-eslint/parser": "~5.
|
|
87
|
+
"@typescript-eslint/eslint-plugin": "~5.38",
|
|
88
|
+
"@typescript-eslint/parser": "~5.38",
|
|
88
89
|
"add-dist-header": "~0.2",
|
|
89
90
|
"assert-deep-strict-equal": "~1.0",
|
|
90
|
-
"
|
|
91
|
+
"copy-file-util": "~0.1",
|
|
92
|
+
"copy-folder-cli": "~0.1",
|
|
91
93
|
"eslint": "~8.23",
|
|
92
94
|
"jshint": "~2.13",
|
|
93
95
|
"merge-stream": "~2.0",
|