w3c-html-validator 1.1.1 → 1.1.2

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
@@ -1,7 +1,7 @@
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
- _A package for testing HTML files or URLs against the W3C validator_
4
+ _Check the markup validity of HTML files using the W3C validator_
5
5
 
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)
@@ -57,10 +57,11 @@ width=800 alt=screenshot>
57
57
  Option value `'warning'` also skips `'info'`.
58
58
 
59
59
  ### w3cHtmlValidator.reporter(options)
60
- | Name (key) | Type | Default | Description |
61
- | :-------------- | :--------- | :------ | :------------------------------------------------------------- |
62
- | `maxMessageLen` | **number** | `null` | Trim validation messages to not exceed a maximum length. |
63
- | `title` | **string** | `null` | Override display title (useful for naming HTML string inputs). |
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
  ## 4) TypeScript Declarations
66
67
  The **TypeScript Declaration File** file is [w3c-html-validator.d.ts](dist/w3c-html-validator.d.ts)
@@ -101,27 +102,35 @@ describe('Home page', () => {
101
102
  ```
102
103
 
103
104
  ## 6) Command Line
104
- Example CLI usage:
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 --save-dev w3c-html-validator
107
- $ npx w3c-html-validator docs/*.html flyer.html
108
- $ npx w3c-html-validator docs #validate html files in a folder
109
- $ npx w3c-html-validator #validate all html files in project
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
+ $ html-validator #validate all html files in project
110
113
  ```
111
114
  or as an npm script in **package.json**:
112
115
  ```json
113
116
  "scripts": {
114
- "validate": "w3c-html-validator docs/*.html flyer.html",
115
- "folder": "w3c-html-validator docs",
116
- "all": "w3c-html-validator"
117
+ "validate": "html-validator docs/*.html flyer.html",
118
+ "one-folder": "html-validator docs",
119
+ "all": "html-validator"
117
120
  },
118
121
  ```
119
- Passing no parameters defaults to validating all HTML files in the projects (skipping the
122
+ Passing no parameters defaults to validating all HTML files in the project (skipping the
120
123
  **node_modules** folder).
121
124
 
122
125
  <br>
123
126
 
124
127
  ---
128
+ **Build Tools**
129
+ - 🎋 [add-dist-header](https://github.com/center-key/add-dist-header):&nbsp; _Prepend a one-line header comment (with license notice) to distribution files_
130
+ - 📄 [copy-file-util](https://github.com/center-key/copy-file-util):&nbsp; _Copy or rename a file (CLI tool designed for use in npm scripts)_
131
+ - 📂 [copy-folder-cli](https://github.com/center-key/copy-folder-cli):&nbsp; _Recursively copy a folder (CLI tool designed for use in npm scripts)_
132
+ - 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator):&nbsp; _Check the markup validity of HTML files using the W3C validator_
133
+
125
134
  Feel free to submit questions at:<br>
126
135
  [github.com/center-key/w3c-html-validator/issues](https://github.com/center-key/w3c-html-validator/issues)
127
136
 
package/bin/cli.js CHANGED
@@ -6,40 +6,53 @@
6
6
 
7
7
  // Usage in package.json:
8
8
  // "scripts": {
9
- // "validate": "w3c-html-validator docs/*.html flyer.html",
10
- // "all": "w3c-html-validator"
9
+ // "validate": "html-validator docs/*.html flyer.html",
10
+ // "all": "html-validator"
11
11
  // },
12
12
  //
13
13
  // Usage from command line:
14
- // $ npx w3c-html-validator docs/*.html flyer.html
15
- // $ npx w3c-html-validator #validate all html files in project
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 args = process.argv.slice(2);
30
- const flags = args.filter(arg => /^-/.test(arg));
31
- const files = args.filter(arg => !/^-/.test(arg));
30
+ const validFlags = ['quiet'];
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 };
32
40
 
33
41
  // 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
42
  const keep = (filename) => !filename.includes('node_modules/');
38
43
  const readFolder = (folder) => glob.sync(folder + '**/*.html', { ignore: '**/node_modules/**/*' });
39
44
  const expandFolder = (file) => lstatSync(file).isDirectory() ? readFolder(file + '/') : file;
40
45
  const getFilenames = () => [...new Set(files.map(expandFolder).flat().filter(keep))].sort();
41
46
  const filenames = files.length ? getFilenames() : readFolder('');
42
- if (filenames.length > 1)
47
+ const error =
48
+ invalidFlag ? 'Invalid flag: ' + invalidFlag :
49
+ !files.length ? 'Missing file parameter.' :
50
+ !filenames.length ? 'No files to validate.' :
51
+ null;
52
+ if (error)
53
+ throw Error('[w3c-html-validator] ' + error);
54
+ if (filenames.length > 1 && !mode.quiet)
43
55
  log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + filenames.length));
44
- filenames.forEach(file =>
45
- w3cHtmlValidator.validate({ filename: file }).then(w3cHtmlValidator.reporter));
56
+ const reporterOptions = { quiet: mode.quiet };
57
+ const handleReport = (report) => w3cHtmlValidator.reporter(report, reporterOptions);
58
+ filenames.forEach(file => w3cHtmlValidator.validate({ filename: file }).then(handleReport));
@@ -1,4 +1,4 @@
1
- //! w3c-html-validator v1.1.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.1.2 ~~ 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 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.1.2 ~~ 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.1',
8
+ version: '1.1.2',
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
- log(chalk.gray('w3c-html-validator'), status, chalk.blue.bold(title), chalk.white(count));
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 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.1.2 ~~ 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.1',
23
+ version: '1.1.2',
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
- (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
+ 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.1",
4
- "description": "A package for testing HTML files or URLs against the W3C validator (written in functional TypeScript)",
3
+ "version": "1.1.2",
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 node_modules,build,dist",
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": "cpy build/umd/w3c-html-validator.js build --rename=w3c-html-validator.umd.cjs --flat=true",
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.37",
87
- "@typescript-eslint/parser": "~5.37",
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
- "cpy-cli": "~4.2",
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",