w3c-html-validator 1.3.2 → 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/README.md CHANGED
@@ -63,18 +63,24 @@ Command-line flags:
63
63
  Examples:
64
64
  - `html-validator`<br>
65
65
  Validate all HTML files in the project.
66
+
66
67
  - `html-validator --exclude=build,tmp`<br>
67
68
  Slip all files which have "build" or "tmp" anywhere in their pathname or filename.
68
- - `html-validator docs/*.html "--ignore=Trailing slash on void elements"`<br>
69
+
70
+ - `html-validator docs/*.html '--ignore=Trailing slash on void elements'`<br>
69
71
  Allow the ugly slashes of self-closing tags despite XHTML being a hideous scourge on the web.
70
- - `html-validator docs/*.html "--ignore=/^Duplicate ID/"`<br>
71
- Use a RegEx (regular expression) to skip all messages that start with "Duplicate ID".
72
+
73
+ - `html-validator docs/*.html '--ignore=/^Duplicate ID/'`<br>
74
+ Use a RegEx (regular expression) to skip all validation messages that start with "Duplicate ID".
75
+
72
76
  - `html-validator --quiet`<br>
73
- Suppress "pass" messages.
77
+ Suppress "pass" status messages.
78
+
74
79
  - `html-validator docs --delay=200`<br>
75
80
  Validate all HTML files in the "docs" folder at a rate of 1 file per 200 ms (default is 500 ms).
81
+
76
82
  - `html-validator docs --trim=30 --continue`<br>
77
- Truncate messages to 30 characters and do not abort CI if validation fails.
83
+ Truncate validation messages to 30 characters and do not abort CI if validation fails.
78
84
 
79
85
  ## D) Application Code and Testing Frameworks
80
86
  In addition to the CLI interface, the **w3c-html-validator** package can also be imported and called directly in ESM and TypeScript projects.
@@ -118,7 +124,7 @@ Option value `'warning'` also skips `'info'`.
118
124
  | :--------------- | :---------- | :------ | :-------------------------------------------------------------- |
119
125
  | `continueOnFail` | **boolean** | `false` | Report messages but do not throw an error if validation failed. |
120
126
  | `maxMessageLen` | **number** | `null` | Trim validation messages to not exceed a maximum length. |
121
- | `quiet` | **boolean** | `false` | Suppress messages for successful validations. |
127
+ | `quiet` | **boolean** | `false` | Suppress status messages for successful validations. |
122
128
  | `title` | **string** | `null` | Override display title (useful for naming HTML string inputs). |
123
129
 
124
130
  ### 3. TypeScript declarations
package/bin/cli.js CHANGED
@@ -21,10 +21,10 @@
21
21
 
22
22
  // Imports
23
23
  import { cliArgvUtil } from 'cli-argv-util';
24
+ import { globSync } from 'glob';
24
25
  import { w3cHtmlValidator } from '../dist/w3c-html-validator.js';
25
26
  import chalk from 'chalk';
26
27
  import fs from 'fs';
27
- import glob from 'glob';
28
28
  import log from 'fancy-log';
29
29
 
30
30
  // Parameters and flags
@@ -32,12 +32,12 @@ 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 = parseInt(cli.flagMap.delay) || 500; //default half second debounce pause
36
- const trim = parseInt(cli.flagMap.trim) || null;
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/');
40
- const readFolder = (folder) => glob.sync(folder + '**/*.html', { ignore: '**/node_modules/**/*' });
40
+ const readFolder = (folder) => globSync(folder + '**/*.html', { ignore: '**/node_modules/**/*' });
41
41
  const expandFolder = (file) => fs.lstatSync(file).isDirectory() ? readFolder(file + '/') : file;
42
42
  const getFilenames = () => [...new Set(files.map(expandFolder).flat().filter(keep))].sort();
43
43
  const list = files.length ? getFilenames() : readFolder('');
@@ -1,4 +1,4 @@
1
- //! w3c-html-validator v1.3.2 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.4.0 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
2
2
 
3
3
  export type ValidatorSettings = {
4
4
  html: string;
@@ -1,11 +1,11 @@
1
- //! w3c-html-validator v1.3.2 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
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.3.2',
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['response'];
73
+ const response = reason.response;
74
74
  const getMsg = () => [response.status, response.res.statusMessage, response.request.url];
75
- const message = response ? getMsg() : [reason['errno'], reason.message];
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
  };
@@ -102,7 +102,7 @@ const w3cHtmlValidator = {
102
102
  };
103
103
  const logMessage = (message) => {
104
104
  var _a, _b, _c, _d;
105
- const type = (_a = message.subType) !== null && _a !== void 0 ? _a : message.type;
105
+ const type = ((_a = message.subType) !== null && _a !== void 0 ? _a : message.type);
106
106
  const typeColor = (_b = typeColorMap[type]) !== null && _b !== void 0 ? _b : chalk.redBright.bold;
107
107
  const location = `line ${message.lastLine}, column ${message.firstColumn}:`;
108
108
  const lineText = (_c = message.extract) === null || _c === void 0 ? void 0 : _c.replace(/\n/g, '\\n');
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "w3c-html-validator",
3
- "version": "1.3.2",
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.umd.cjs",
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,45 +61,45 @@
62
61
  }
63
62
  },
64
63
  "runScriptsConfig": {
64
+ "clean": [
65
+ "rimraf build dist"
66
+ ],
65
67
  "build": [
66
- "rimraf build dist **/.DS_Store",
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
  },
80
79
  "dependencies": {
81
80
  "chalk": "~5.2",
82
- "cli-argv-util": "~0.1",
81
+ "cli-argv-util": "~1.0",
83
82
  "fancy-log": "~2.0",
84
- "glob": "~8.1",
83
+ "glob": "~10.2",
85
84
  "superagent": "~8.0"
86
85
  },
87
86
  "devDependencies": {
88
87
  "@types/fancy-log": "~2.0",
89
- "@types/glob": "~8.0",
90
- "@types/node": "~18.13",
88
+ "@types/glob": "~8.1",
89
+ "@types/node": "~20.3",
91
90
  "@types/superagent": "~4.1",
92
- "@typescript-eslint/eslint-plugin": "~5.52",
93
- "@typescript-eslint/parser": "~5.52",
94
- "add-dist-header": "~0.3",
91
+ "@typescript-eslint/eslint-plugin": "~5.60",
92
+ "@typescript-eslint/parser": "~5.60",
93
+ "add-dist-header": "~1.0",
95
94
  "assert-deep-strict-equal": "~1.0",
96
- "copy-file-util": "~0.1",
97
- "copy-folder-util": "~0.2",
98
- "eslint": "~8.34",
95
+ "copy-file-util": "~1.0",
96
+ "copy-folder-util": "~1.0",
97
+ "eslint": "~8.43",
99
98
  "jshint": "~2.13",
100
99
  "merge-stream": "~2.0",
101
100
  "mocha": "~10.2",
102
- "rimraf": "3",
103
- "run-scripts-util": "~0.1",
104
- "typescript": "~4.9"
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.2 ~~ 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.2',
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
- });