w3c-html-validator 1.0.1 → 1.0.4

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
@@ -6,7 +6,7 @@ _A package for testing HTML files or URLs against the W3C validator_
6
6
  [![License:MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/center-key/w3c-html-validator/blob/main/LICENSE.txt)
7
7
  [![npm](https://img.shields.io/npm/v/w3c-html-validator.svg)](https://www.npmjs.com/package/w3c-html-validator)
8
8
  [![Vulnerabilities](https://snyk.io/test/github/center-key/w3c-html-validator/badge.svg)](https://snyk.io/test/github/center-key/w3c-html-validator)
9
- [![Build](https://github.com/center-key/w3c-html-validator/workflows/build/badge.svg)](https://github.com/center-key/w3c-html-validator/actions?query=workflow%3Abuild)
9
+ [![Build](https://github.com/center-key/w3c-html-validator/workflows/build/badge.svg)](https://github.com/center-key/w3c-html-validator/actions/workflows/run-spec-on-push.yaml)
10
10
 
11
11
  ## 1) Setup
12
12
 
@@ -42,7 +42,7 @@ $ node examples.js
42
42
  width=800 alt=screenshot>
43
43
 
44
44
  ## 3) Options
45
- ### validate()
45
+ ### w3cHtmlValidator.validate(options)
46
46
  | Name (key) | Type | Default | Description |
47
47
  | :--------------- | :---------------------- | :------------------------------- | :------------------------------------------------------------------- |
48
48
  | `html` | **string** | `null` | HTML string to validate. |
@@ -56,7 +56,7 @@ width=800 alt=screenshot>
56
56
  *The `ignoreMessages` and `ignoreLevel` options only work for `'json'` output. 
57
57
  Option value `'warning'` also skips `'info'`.
58
58
 
59
- ### reporter()
59
+ ### w3cHtmlValidator.reporter(options)
60
60
  | Name (key) | Type | Default | Description |
61
61
  | :-------------- | :--------- | :------ | :------------------------------------------------------------- |
62
62
  | `maxMessageLen` | **number** | `null` | Trim validation messages to not exceed a maximum length. |
@@ -119,6 +119,10 @@ or as an npm script in **package.json**:
119
119
  Passing no parameters defaults to validating all HTML files in the projects (skipping the
120
120
  **node_modules** folder).
121
121
 
122
- ## 7) Gulp Task
123
- This library is available as a Gulp plugin:<br>
124
- https://github.com/center-key/gulp-w3c-html-validator
122
+ <br>
123
+
124
+ ---
125
+ Feel free to submit questions at:<br>
126
+ [github.com/center-key/w3c-html-validator/issues](https://github.com/center-key/w3c-html-validator/issues)
127
+
128
+ [MIT License](LICENSE.txt)
package/bin/cli.js CHANGED
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env node
2
- // w3c-html-validator ~~ MIT License
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 v1.0.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.0.4 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
2
2
 
3
3
  export declare type ValidatorOptions = {
4
4
  html?: string;
@@ -42,6 +42,6 @@ export declare type ReporterOptions = {
42
42
  declare const w3cHtmlValidator: {
43
43
  version: string;
44
44
  validate(options: ValidatorOptions): Promise<ValidatorResults>;
45
- reporter(results: ValidatorResults, options?: ReporterOptions | undefined): ValidatorResults;
45
+ reporter(results: ValidatorResults, options?: ReporterOptions): ValidatorResults;
46
46
  };
47
47
  export { w3cHtmlValidator };
@@ -1,11 +1,11 @@
1
- //! w3c-html-validator v1.0.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.0.4 ~~ 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.0.1',
8
+ version: '1.0.4',
9
9
  validate(options) {
10
10
  const defaults = {
11
11
  checkUrl: 'https://validator.w3.org/nu/',
@@ -13,7 +13,7 @@ const w3cHtmlValidator = {
13
13
  ignoreMessages: null,
14
14
  output: 'json',
15
15
  };
16
- const settings = { ...defaults, ...options };
16
+ const settings = Object.assign(Object.assign({}, defaults), options);
17
17
  if (!settings.html && !settings.filename && !settings.website)
18
18
  throw Error('[w3c-html-validator] Must specify the "html", "filename", or "website" option.');
19
19
  if (![null, 'info', 'warning'].includes(settings.ignoreLevel))
@@ -34,51 +34,60 @@ const w3cHtmlValidator = {
34
34
  const json = settings.output === 'json';
35
35
  const success = '<p class="success">';
36
36
  const titleLookup = {
37
- html: 'HTML String (characters: ' + inputHtml?.length + ')',
37
+ html: 'HTML String (characters: ' + (inputHtml === null || inputHtml === void 0 ? void 0 : inputHtml.length) + ')',
38
38
  filename: settings.filename,
39
39
  website: settings.website,
40
40
  };
41
41
  const filterMessages = (response) => {
42
+ var _a, _b;
42
43
  const aboveInfo = (subType) => settings.ignoreLevel === 'info' && !!subType;
43
44
  const aboveIgnoreLevel = (message) => !settings.ignoreLevel || message.type !== 'info' || aboveInfo(message.subType);
44
45
  const skipSubstr = (title) => typeof settings.ignoreMessages === 'string' && title.includes(settings.ignoreMessages);
45
- const skipRegEx = (title) => settings.ignoreMessages?.constructor.name === 'RegExp' &&
46
- settings.ignoreMessages.test(title);
46
+ const skipRegEx = (title) => {
47
+ var _a;
48
+ return ((_a = settings.ignoreMessages) === null || _a === void 0 ? void 0 : _a.constructor.name) === 'RegExp' &&
49
+ settings.ignoreMessages.test(title);
50
+ };
47
51
  const isImportant = (message) => aboveIgnoreLevel(message) && !skipSubstr(message.message) && !skipRegEx(message.message);
48
52
  if (json)
49
- response.body.messages = response.body.messages?.filter(isImportant) ?? [];
53
+ response.body.messages = (_b = (_a = response.body.messages) === null || _a === void 0 ? void 0 : _a.filter(isImportant)) !== null && _b !== void 0 ? _b : [];
50
54
  return response;
51
55
  };
52
- const toValidatorResults = (response) => ({
53
- validates: json ? !response.body.messages.length : response.text.includes(success),
54
- mode: mode,
55
- title: titleLookup[mode],
56
- html: inputHtml,
57
- filename: settings.filename || null,
58
- website: settings.website || null,
59
- output: settings.output,
60
- status: response.statusCode,
61
- messages: json ? response.body.messages : null,
62
- display: json ? null : response.text,
63
- });
56
+ const toValidatorResults = (response) => {
57
+ var _a;
58
+ return ({
59
+ validates: json ? !response.body.messages.length : !!((_a = response.text) === null || _a === void 0 ? void 0 : _a.includes(success)),
60
+ mode: mode,
61
+ title: titleLookup[mode],
62
+ html: inputHtml,
63
+ filename: settings.filename || null,
64
+ website: settings.website || null,
65
+ output: settings.output,
66
+ status: response.statusCode || -1,
67
+ messages: json ? response.body.messages : null,
68
+ display: json ? null : response.text,
69
+ });
70
+ };
64
71
  const handleError = (reason) => {
65
72
  const response = reason['response'];
66
- const message = [response.status, response.res.statusMessage, response.request.url];
67
- const networkError = { type: 'network-error', message: message.join(' ') };
68
- return toValidatorResults({ ...response, ...{ body: { messages: [networkError] } } });
73
+ const getMsg = () => [response.status, response.res.statusMessage, response.request.url];
74
+ const message = response ? getMsg() : [reason['errno'], reason.message];
75
+ const networkErr = { type: 'network-error', message: message.join(' ') };
76
+ return toValidatorResults(Object.assign(Object.assign({}, response), { body: { messages: [networkErr] } }));
69
77
  };
70
78
  return w3cRequest.then(filterMessages).then(toValidatorResults).catch(handleError);
71
79
  },
72
80
  reporter(results, options) {
81
+ var _a, _b;
73
82
  const defaults = {
74
83
  maxMessageLen: null,
75
84
  title: null,
76
85
  };
77
- const settings = { ...defaults, ...options };
78
- if (typeof results?.validates !== 'boolean')
86
+ const settings = Object.assign(Object.assign({}, defaults), options);
87
+ if (typeof (results === null || results === void 0 ? void 0 : results.validates) !== 'boolean')
79
88
  throw Error('[w3c-html-validator] Invalid results for reporter(): ' + String(results));
80
- const messages = results.messages ?? [];
81
- const title = settings.title ?? results.title;
89
+ const messages = (_a = results.messages) !== null && _a !== void 0 ? _a : [];
90
+ const title = (_b = settings.title) !== null && _b !== void 0 ? _b : results.title;
82
91
  const fail = 'fail (messages: ' + messages.length + ')';
83
92
  const status = results.validates ? chalk.green('pass') : chalk.red.bold(fail);
84
93
  log(chalk.gray('w3c-html-validator'), chalk.blue.bold(title), status);
@@ -88,11 +97,12 @@ const w3cHtmlValidator = {
88
97
  info: chalk.white.bold,
89
98
  };
90
99
  const logMessage = (message) => {
100
+ var _a, _b;
91
101
  const type = message.subType || message.type;
92
102
  const typeColor = typeColorMap[type] || chalk.redBright.bold;
93
103
  const location = `line ${message.lastLine}, column ${message.firstColumn}:`;
94
- const lineText = message.extract?.replace(/\n/g, '\\n');
95
- const maxLen = settings.maxMessageLen ?? undefined;
104
+ const lineText = (_a = message.extract) === null || _a === void 0 ? void 0 : _a.replace(/\n/g, '\\n');
105
+ const maxLen = (_b = settings.maxMessageLen) !== null && _b !== void 0 ? _b : undefined;
96
106
  log(typeColor('HTML ' + type + ':'), message.message.substring(0, maxLen));
97
107
  if (message.lastLine)
98
108
  log(chalk.white(location), chalk.magenta(lineText));
@@ -1,4 +1,4 @@
1
- //! w3c-html-validator v1.0.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.0.4 ~~ 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.0.1',
23
+ version: '1.0.4',
24
24
  validate(options) {
25
25
  const defaults = {
26
26
  checkUrl: 'https://validator.w3.org/nu/',
@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  ignoreMessages: null,
29
29
  output: 'json',
30
30
  };
31
- const settings = { ...defaults, ...options };
31
+ const settings = Object.assign(Object.assign({}, defaults), options);
32
32
  if (!settings.html && !settings.filename && !settings.website)
33
33
  throw Error('[w3c-html-validator] Must specify the "html", "filename", or "website" option.');
34
34
  if (![null, 'info', 'warning'].includes(settings.ignoreLevel))
@@ -49,51 +49,60 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
49
49
  const json = settings.output === 'json';
50
50
  const success = '<p class="success">';
51
51
  const titleLookup = {
52
- html: 'HTML String (characters: ' + inputHtml?.length + ')',
52
+ html: 'HTML String (characters: ' + (inputHtml === null || inputHtml === void 0 ? void 0 : inputHtml.length) + ')',
53
53
  filename: settings.filename,
54
54
  website: settings.website,
55
55
  };
56
56
  const filterMessages = (response) => {
57
+ var _a, _b;
57
58
  const aboveInfo = (subType) => settings.ignoreLevel === 'info' && !!subType;
58
59
  const aboveIgnoreLevel = (message) => !settings.ignoreLevel || message.type !== 'info' || aboveInfo(message.subType);
59
60
  const skipSubstr = (title) => typeof settings.ignoreMessages === 'string' && title.includes(settings.ignoreMessages);
60
- const skipRegEx = (title) => settings.ignoreMessages?.constructor.name === 'RegExp' &&
61
- settings.ignoreMessages.test(title);
61
+ const skipRegEx = (title) => {
62
+ var _a;
63
+ return ((_a = settings.ignoreMessages) === null || _a === void 0 ? void 0 : _a.constructor.name) === 'RegExp' &&
64
+ settings.ignoreMessages.test(title);
65
+ };
62
66
  const isImportant = (message) => aboveIgnoreLevel(message) && !skipSubstr(message.message) && !skipRegEx(message.message);
63
67
  if (json)
64
- response.body.messages = response.body.messages?.filter(isImportant) ?? [];
68
+ response.body.messages = (_b = (_a = response.body.messages) === null || _a === void 0 ? void 0 : _a.filter(isImportant)) !== null && _b !== void 0 ? _b : [];
65
69
  return response;
66
70
  };
67
- const toValidatorResults = (response) => ({
68
- validates: json ? !response.body.messages.length : response.text.includes(success),
69
- mode: mode,
70
- title: titleLookup[mode],
71
- html: inputHtml,
72
- filename: settings.filename || null,
73
- website: settings.website || null,
74
- output: settings.output,
75
- status: response.statusCode,
76
- messages: json ? response.body.messages : null,
77
- display: json ? null : response.text,
78
- });
71
+ const toValidatorResults = (response) => {
72
+ var _a;
73
+ return ({
74
+ validates: json ? !response.body.messages.length : !!((_a = response.text) === null || _a === void 0 ? void 0 : _a.includes(success)),
75
+ mode: mode,
76
+ title: titleLookup[mode],
77
+ html: inputHtml,
78
+ filename: settings.filename || null,
79
+ website: settings.website || null,
80
+ output: settings.output,
81
+ status: response.statusCode || -1,
82
+ messages: json ? response.body.messages : null,
83
+ display: json ? null : response.text,
84
+ });
85
+ };
79
86
  const handleError = (reason) => {
80
87
  const response = reason['response'];
81
- const message = [response.status, response.res.statusMessage, response.request.url];
82
- const networkError = { type: 'network-error', message: message.join(' ') };
83
- return toValidatorResults({ ...response, ...{ body: { messages: [networkError] } } });
88
+ const getMsg = () => [response.status, response.res.statusMessage, response.request.url];
89
+ const message = response ? getMsg() : [reason['errno'], reason.message];
90
+ const networkErr = { type: 'network-error', message: message.join(' ') };
91
+ return toValidatorResults(Object.assign(Object.assign({}, response), { body: { messages: [networkErr] } }));
84
92
  };
85
93
  return w3cRequest.then(filterMessages).then(toValidatorResults).catch(handleError);
86
94
  },
87
95
  reporter(results, options) {
96
+ var _a, _b;
88
97
  const defaults = {
89
98
  maxMessageLen: null,
90
99
  title: null,
91
100
  };
92
- const settings = { ...defaults, ...options };
93
- if (typeof results?.validates !== 'boolean')
101
+ const settings = Object.assign(Object.assign({}, defaults), options);
102
+ if (typeof (results === null || results === void 0 ? void 0 : results.validates) !== 'boolean')
94
103
  throw Error('[w3c-html-validator] Invalid results for reporter(): ' + String(results));
95
- const messages = results.messages ?? [];
96
- const title = settings.title ?? results.title;
104
+ const messages = (_a = results.messages) !== null && _a !== void 0 ? _a : [];
105
+ const title = (_b = settings.title) !== null && _b !== void 0 ? _b : results.title;
97
106
  const fail = 'fail (messages: ' + messages.length + ')';
98
107
  const status = results.validates ? chalk_1.default.green('pass') : chalk_1.default.red.bold(fail);
99
108
  (0, fancy_log_1.default)(chalk_1.default.gray('w3c-html-validator'), chalk_1.default.blue.bold(title), status);
@@ -103,11 +112,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
103
112
  info: chalk_1.default.white.bold,
104
113
  };
105
114
  const logMessage = (message) => {
115
+ var _a, _b;
106
116
  const type = message.subType || message.type;
107
117
  const typeColor = typeColorMap[type] || chalk_1.default.redBright.bold;
108
118
  const location = `line ${message.lastLine}, column ${message.firstColumn}:`;
109
- const lineText = message.extract?.replace(/\n/g, '\\n');
110
- const maxLen = settings.maxMessageLen ?? undefined;
119
+ const lineText = (_a = message.extract) === null || _a === void 0 ? void 0 : _a.replace(/\n/g, '\\n');
120
+ const maxLen = (_b = settings.maxMessageLen) !== null && _b !== void 0 ? _b : undefined;
111
121
  (0, fancy_log_1.default)(typeColor('HTML ' + type + ':'), message.message.substring(0, maxLen));
112
122
  if (message.lastLine)
113
123
  (0, fancy_log_1.default)(chalk_1.default.white(location), chalk_1.default.magenta(lineText));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "w3c-html-validator",
3
- "version": "1.0.1",
4
- "description": "A package for testing HTML files or URLs against the W3C validator (written in TypeScript)",
3
+ "version": "1.0.4",
4
+ "description": "A package for testing HTML files or URLs against the W3C validator (written in functional TypeScript)",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "module": "dist/w3c-html-validator.js",
@@ -66,7 +66,7 @@
66
66
  "step:03": "eslint --max-warnings 0 . --ext .ts",
67
67
  "step:04": "tsc",
68
68
  "step:05": "tsc --module UMD --outDir build/umd",
69
- "step:06": "cpy build/umd/w3c-html-validator.js build --rename=w3c-html-validator.umd.cjs",
69
+ "step:06": "cpy build/umd/w3c-html-validator.js build --rename=w3c-html-validator.umd.cjs --flat=true",
70
70
  "step:07": "add-dist-header build dist",
71
71
  "pretest": "npm-run-all step:*",
72
72
  "test": "mocha spec/*.spec.js --timeout 5000",
@@ -75,25 +75,25 @@
75
75
  "dependencies": {
76
76
  "chalk": "~5.0",
77
77
  "fancy-log": "~2.0",
78
- "glob": "~7.2",
79
- "superagent": "~7.1"
78
+ "glob": "~8.0",
79
+ "superagent": "~8.0"
80
80
  },
81
81
  "devDependencies": {
82
- "@types/fancy-log": "~1.3",
82
+ "@types/fancy-log": "~2.0",
83
83
  "@types/glob": "~7.2",
84
- "@types/node": "~17.0",
84
+ "@types/node": "~18.0",
85
85
  "@types/superagent": "~4.1",
86
- "@typescript-eslint/eslint-plugin": "~5.10",
87
- "@typescript-eslint/parser": "~5.10",
86
+ "@typescript-eslint/eslint-plugin": "~5.30",
87
+ "@typescript-eslint/parser": "~5.30",
88
88
  "add-dist-header": "~0.1",
89
89
  "assert-deep-strict-equal": "~1.0",
90
- "cpy-cli": "~3.1",
91
- "eslint": "~8.7",
90
+ "cpy-cli": "~4.1",
91
+ "eslint": "~8.19",
92
92
  "jshint": "~2.13",
93
93
  "merge-stream": "~2.0",
94
- "mocha": "~9.2",
95
- "npm-run-all2": "~5.0",
94
+ "mocha": "~10.0",
95
+ "npm-run-all2": "~6.0",
96
96
  "rimraf": "~3.0",
97
- "typescript": "~4.5"
97
+ "typescript": "~4.7"
98
98
  }
99
99
  }