w3c-html-validator 0.8.0 → 1.0.1

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/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 individual contributors to w3c-html-validator
3
+ Copyright (c) 2021-2022 individual contributors to w3c-html-validator
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/bin/cli.js CHANGED
@@ -28,14 +28,15 @@ const flags = args.filter(arg => /^-/.test(arg));
28
28
  const files = args.filter(arg => !/^-/.test(arg));
29
29
 
30
30
  // Validator
31
- log('w3c-html-validator');
31
+ const exit = (message) => (console.error('[w3c-html-validator] ' + message), process.exit(1));
32
32
  if (flags.length)
33
- log(chalk.red('Flags not supported:'), flags.join(' '));
33
+ exit('Flags not supported: ' + flags.join(' '));
34
34
  const keep = (filename) => !filename.includes('node_modules/');
35
35
  const readFolder = (folder) => glob.sync(folder + '**/*.html', { ignore: '**/node_modules/**/*' });
36
36
  const expandFolder = (file) => lstatSync(file).isDirectory() ? readFolder(file + '/') : file;
37
37
  const getFilenames = () => [...new Set(files.map(expandFolder).flat().filter(keep))].sort();
38
38
  const filenames = files.length ? getFilenames() : readFolder('');
39
- log(chalk.gray('files:'), chalk.cyan(filenames.length));
39
+ if (filenames.length > 1)
40
+ log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + filenames.length));
40
41
  filenames.forEach(file =>
41
42
  w3cHtmlValidator.validate({ filename: file }).then(w3cHtmlValidator.reporter));
@@ -1,4 +1,4 @@
1
- //! w3c-html-validator v0.8.0 ~ https://github.com/center-key/w3c-html-validator ~ MIT License
1
+ //! w3c-html-validator v1.0.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
2
2
 
3
3
  export declare type ValidatorOptions = {
4
4
  html?: string;
@@ -10,7 +10,7 @@ export declare type ValidatorOptions = {
10
10
  output?: ValidatorResultsOutput;
11
11
  };
12
12
  export declare type ValidatorResultsMessage = {
13
- type: 'info' | 'error' | 'non-document-error';
13
+ type: 'info' | 'error' | 'non-document-error' | 'network-error';
14
14
  subType?: 'warning' | 'fatal' | 'io' | 'schema' | 'internal';
15
15
  message: string;
16
16
  extract: string;
@@ -1,11 +1,11 @@
1
- //! w3c-html-validator v0.8.0 ~ https://github.com/center-key/w3c-html-validator ~ MIT License
1
+ //! w3c-html-validator v1.0.1 ~~ 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: '0.8.0',
8
+ version: '1.0.1',
9
9
  validate(options) {
10
10
  const defaults = {
11
11
  checkUrl: 'https://validator.w3.org/nu/',
@@ -15,11 +15,11 @@ const w3cHtmlValidator = {
15
15
  };
16
16
  const settings = { ...defaults, ...options };
17
17
  if (!settings.html && !settings.filename && !settings.website)
18
- throw Error('Must specify the "html", "filename", or "website" option.');
18
+ throw Error('[w3c-html-validator] Must specify the "html", "filename", or "website" option.');
19
19
  if (![null, 'info', 'warning'].includes(settings.ignoreLevel))
20
20
  throw Error('[w3c-html-validator] Invalid ignoreLevel option: ' + settings.ignoreLevel);
21
21
  if (settings.output !== 'json' && settings.output !== 'html')
22
- throw Error('Option "output" must be "json" or "html".');
22
+ throw Error('[w3c-html-validator] Option "output" must be "json" or "html".');
23
23
  const mode = settings.html ? 'html' : settings.filename ? 'filename' : 'website';
24
24
  const readFile = () => settings.filename ? readFileSync(settings.filename, 'utf8') : null;
25
25
  const inputHtml = settings.html || readFile();
@@ -61,7 +61,13 @@ const w3cHtmlValidator = {
61
61
  messages: json ? response.body.messages : null,
62
62
  display: json ? null : response.text,
63
63
  });
64
- return w3cRequest.then(filterMessages).then(toValidatorResults);
64
+ const handleError = (reason) => {
65
+ 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] } } });
69
+ };
70
+ return w3cRequest.then(filterMessages).then(toValidatorResults).catch(handleError);
65
71
  },
66
72
  reporter(results, options) {
67
73
  const defaults = {
@@ -75,7 +81,7 @@ const w3cHtmlValidator = {
75
81
  const title = settings.title ?? results.title;
76
82
  const fail = 'fail (messages: ' + messages.length + ')';
77
83
  const status = results.validates ? chalk.green('pass') : chalk.red.bold(fail);
78
- log(chalk.blue.bold(title), chalk.gray('validation:'), status);
84
+ log(chalk.gray('w3c-html-validator'), chalk.blue.bold(title), status);
79
85
  const typeColorMap = {
80
86
  error: chalk.red.bold,
81
87
  warning: chalk.yellow.bold,
@@ -89,7 +95,7 @@ const w3cHtmlValidator = {
89
95
  const maxLen = settings.maxMessageLen ?? undefined;
90
96
  log(typeColor('HTML ' + type + ':'), message.message.substring(0, maxLen));
91
97
  if (message.lastLine)
92
- log(chalk.gray(location), chalk.cyan(lineText));
98
+ log(chalk.white(location), chalk.magenta(lineText));
93
99
  };
94
100
  messages.forEach(logMessage);
95
101
  return results;
@@ -1,4 +1,4 @@
1
- //! w3c-html-validator v0.8.0 ~ https://github.com/center-key/w3c-html-validator ~ MIT License
1
+ //! w3c-html-validator v1.0.1 ~~ 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: '0.8.0',
23
+ version: '1.0.1',
24
24
  validate(options) {
25
25
  const defaults = {
26
26
  checkUrl: 'https://validator.w3.org/nu/',
@@ -30,11 +30,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
30
30
  };
31
31
  const settings = { ...defaults, ...options };
32
32
  if (!settings.html && !settings.filename && !settings.website)
33
- throw Error('Must specify the "html", "filename", or "website" option.');
33
+ throw Error('[w3c-html-validator] Must specify the "html", "filename", or "website" option.');
34
34
  if (![null, 'info', 'warning'].includes(settings.ignoreLevel))
35
35
  throw Error('[w3c-html-validator] Invalid ignoreLevel option: ' + settings.ignoreLevel);
36
36
  if (settings.output !== 'json' && settings.output !== 'html')
37
- throw Error('Option "output" must be "json" or "html".');
37
+ throw Error('[w3c-html-validator] Option "output" must be "json" or "html".');
38
38
  const mode = settings.html ? 'html' : settings.filename ? 'filename' : 'website';
39
39
  const readFile = () => settings.filename ? (0, fs_1.readFileSync)(settings.filename, 'utf8') : null;
40
40
  const inputHtml = settings.html || readFile();
@@ -76,7 +76,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
76
76
  messages: json ? response.body.messages : null,
77
77
  display: json ? null : response.text,
78
78
  });
79
- return w3cRequest.then(filterMessages).then(toValidatorResults);
79
+ const handleError = (reason) => {
80
+ 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] } } });
84
+ };
85
+ return w3cRequest.then(filterMessages).then(toValidatorResults).catch(handleError);
80
86
  },
81
87
  reporter(results, options) {
82
88
  const defaults = {
@@ -90,7 +96,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
90
96
  const title = settings.title ?? results.title;
91
97
  const fail = 'fail (messages: ' + messages.length + ')';
92
98
  const status = results.validates ? chalk_1.default.green('pass') : chalk_1.default.red.bold(fail);
93
- (0, fancy_log_1.default)(chalk_1.default.blue.bold(title), chalk_1.default.gray('validation:'), status);
99
+ (0, fancy_log_1.default)(chalk_1.default.gray('w3c-html-validator'), chalk_1.default.blue.bold(title), status);
94
100
  const typeColorMap = {
95
101
  error: chalk_1.default.red.bold,
96
102
  warning: chalk_1.default.yellow.bold,
@@ -104,7 +110,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
104
110
  const maxLen = settings.maxMessageLen ?? undefined;
105
111
  (0, fancy_log_1.default)(typeColor('HTML ' + type + ':'), message.message.substring(0, maxLen));
106
112
  if (message.lastLine)
107
- (0, fancy_log_1.default)(chalk_1.default.gray(location), chalk_1.default.cyan(lineText));
113
+ (0, fancy_log_1.default)(chalk_1.default.white(location), chalk_1.default.magenta(lineText));
108
114
  };
109
115
  messages.forEach(logMessage);
110
116
  return results;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w3c-html-validator",
3
- "version": "0.8.0",
3
+ "version": "1.0.1",
4
4
  "description": "A package for testing HTML files or URLs against the W3C validator (written in TypeScript)",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -66,33 +66,34 @@
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/*.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",
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",
73
73
  "examples": "node examples.js"
74
74
  },
75
75
  "dependencies": {
76
- "chalk": "~4.1",
77
- "fancy-log": "~1.3",
76
+ "chalk": "~5.0",
77
+ "fancy-log": "~2.0",
78
78
  "glob": "~7.2",
79
- "superagent": "~6.1"
79
+ "superagent": "~7.1"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@types/fancy-log": "~1.3",
83
- "@types/node": "~16.10",
83
+ "@types/glob": "~7.2",
84
+ "@types/node": "~17.0",
84
85
  "@types/superagent": "~4.1",
85
- "@typescript-eslint/eslint-plugin": "~4.32",
86
- "@typescript-eslint/parser": "~4.32",
87
- "add-dist-header": "~0.0",
88
- "assert-deep-strict-equal": "~0.0",
86
+ "@typescript-eslint/eslint-plugin": "~5.10",
87
+ "@typescript-eslint/parser": "~5.10",
88
+ "add-dist-header": "~0.1",
89
+ "assert-deep-strict-equal": "~1.0",
89
90
  "cpy-cli": "~3.1",
90
- "eslint": "~7.32",
91
+ "eslint": "~8.7",
91
92
  "jshint": "~2.13",
92
93
  "merge-stream": "~2.0",
93
- "mocha": "~9.1",
94
+ "mocha": "~9.2",
94
95
  "npm-run-all2": "~5.0",
95
96
  "rimraf": "~3.0",
96
- "typescript": "~4.4"
97
+ "typescript": "~4.5"
97
98
  }
98
99
  }