w3c-html-validator 1.1.2 → 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 +11 -9
- package/bin/cli.js +10 -6
- package/dist/w3c-html-validator.d.ts +1 -1
- package/dist/w3c-html-validator.js +2 -2
- package/dist/w3c-html-validator.umd.cjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ _Check the markup validity of HTML files using the W3C 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
|
| :--------------- | :---------------------- | :------------------------------- | :------------------------------------------------------------------- |
|
|
@@ -63,7 +63,7 @@ Option value `'warning'` also skips `'info'`.
|
|
|
63
63
|
| `quiet` | **boolean** | `false` | Suppress messages for successful validations. |
|
|
64
64
|
| `title` | **string** | `null` | Override display title (useful for naming HTML string inputs). |
|
|
65
65
|
|
|
66
|
-
##
|
|
66
|
+
## D) TypeScript Declarations
|
|
67
67
|
The **TypeScript Declaration File** file is [w3c-html-validator.d.ts](dist/w3c-html-validator.d.ts)
|
|
68
68
|
in the **dist** folder.
|
|
69
69
|
|
|
@@ -83,7 +83,7 @@ type ValidatorResults = {
|
|
|
83
83
|
};
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
##
|
|
86
|
+
## E) Mocha Example
|
|
87
87
|
```javascript
|
|
88
88
|
import assert from 'assert';
|
|
89
89
|
import { w3cHtmlValidator } from 'w3c-html-validator';
|
|
@@ -101,22 +101,24 @@ describe('Home page', () => {
|
|
|
101
101
|
});
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
##
|
|
104
|
+
## F) Command Line
|
|
105
105
|
You can install **w3c-html-validator** globally and then run it anywhere directly from the terminal.
|
|
106
106
|
|
|
107
107
|
Example terminal commands:
|
|
108
108
|
```shell
|
|
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
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
|
|
113
115
|
```
|
|
114
116
|
or as an npm script in **package.json**:
|
|
115
117
|
```json
|
|
116
118
|
"scripts": {
|
|
117
119
|
"validate": "html-validator docs/*.html flyer.html",
|
|
118
120
|
"one-folder": "html-validator docs",
|
|
119
|
-
"all": "html-validator"
|
|
121
|
+
"all": "html-validator --quiet"
|
|
120
122
|
},
|
|
121
123
|
```
|
|
122
124
|
Passing no parameters defaults to validating all HTML files in the project (skipping the
|
package/bin/cli.js
CHANGED
|
@@ -27,7 +27,7 @@ import glob from 'glob';
|
|
|
27
27
|
import log from 'fancy-log';
|
|
28
28
|
|
|
29
29
|
// Parameters
|
|
30
|
-
const validFlags = ['quiet'];
|
|
30
|
+
const validFlags = ['quiet', 'trim'];
|
|
31
31
|
const args = process.argv.slice(2);
|
|
32
32
|
const flags = args.filter(arg => /^--/.test(arg));
|
|
33
33
|
const flagMap = Object.fromEntries(flags.map(flag => flag.replace(/^--/, '').split('=')));
|
|
@@ -36,7 +36,8 @@ const params = args.filter(arg => !/^--/.test(arg));
|
|
|
36
36
|
|
|
37
37
|
// Data
|
|
38
38
|
const files = params;
|
|
39
|
-
const mode = { quiet: 'quiet' in flagMap };
|
|
39
|
+
const mode = { quiet: 'quiet' in flagMap, trim: 'trim' in flagMap };
|
|
40
|
+
const trim = parseInt(flagMap.trim) || null;
|
|
40
41
|
|
|
41
42
|
// Validator
|
|
42
43
|
const keep = (filename) => !filename.includes('node_modules/');
|
|
@@ -45,14 +46,17 @@ const expandFolder = (file) => lstatSync(file).isDirectory() ? readFolder(file +
|
|
|
45
46
|
const getFilenames = () => [...new Set(files.map(expandFolder).flat().filter(keep))].sort();
|
|
46
47
|
const filenames = files.length ? getFilenames() : readFolder('');
|
|
47
48
|
const error =
|
|
48
|
-
invalidFlag ?
|
|
49
|
-
!
|
|
50
|
-
|
|
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.' :
|
|
51
52
|
null;
|
|
52
53
|
if (error)
|
|
53
54
|
throw Error('[w3c-html-validator] ' + error);
|
|
54
55
|
if (filenames.length > 1 && !mode.quiet)
|
|
55
56
|
log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + filenames.length));
|
|
56
|
-
const reporterOptions = {
|
|
57
|
+
const reporterOptions = {
|
|
58
|
+
quiet: mode.quiet,
|
|
59
|
+
maxMessageLen: trim,
|
|
60
|
+
};
|
|
57
61
|
const handleReport = (report) => w3cHtmlValidator.reporter(report, reporterOptions);
|
|
58
62
|
filenames.forEach(file => w3cHtmlValidator.validate({ filename: file }).then(handleReport));
|
|
@@ -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 = {
|
|
@@ -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 = {
|