w3c-html-validator 0.7.9 → 1.0.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/LICENSE.txt +1 -1
- package/bin/cli.js +4 -3
- package/dist/w3c-html-validator.d.ts +3 -3
- package/dist/w3c-html-validator.js +6 -6
- package/dist/w3c-html-validator.umd.cjs +8 -8
- package/package.json +25 -21
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
|
-
|
|
31
|
+
const exit = (message) => (console.error('[w3c-html-validator] ' + message), process.exit(1));
|
|
32
32
|
if (flags.length)
|
|
33
|
-
|
|
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
|
-
|
|
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
|
-
//!
|
|
1
|
+
//! w3c-html-validator v1.0.0 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
export declare type ValidatorOptions = {
|
|
4
4
|
html?: string;
|
|
@@ -36,8 +36,8 @@ export declare type ValidatorResults = {
|
|
|
36
36
|
};
|
|
37
37
|
export declare type ValidatorResultsOutput = ValidatorResults['output'];
|
|
38
38
|
export declare type ReporterOptions = {
|
|
39
|
-
maxMessageLen?: number;
|
|
40
|
-
title?: string;
|
|
39
|
+
maxMessageLen?: number | null;
|
|
40
|
+
title?: string | null;
|
|
41
41
|
};
|
|
42
42
|
declare const w3cHtmlValidator: {
|
|
43
43
|
version: string;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
//!
|
|
1
|
+
//! w3c-html-validator v1.0.0 ~~ 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
|
+
version: '1.0.0',
|
|
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();
|
|
@@ -75,7 +75,7 @@ const w3cHtmlValidator = {
|
|
|
75
75
|
const title = settings.title ?? results.title;
|
|
76
76
|
const fail = 'fail (messages: ' + messages.length + ')';
|
|
77
77
|
const status = results.validates ? chalk.green('pass') : chalk.red.bold(fail);
|
|
78
|
-
log(chalk.
|
|
78
|
+
log(chalk.gray('w3c-html-validator'), chalk.blue.bold(title), status);
|
|
79
79
|
const typeColorMap = {
|
|
80
80
|
error: chalk.red.bold,
|
|
81
81
|
warning: chalk.yellow.bold,
|
|
@@ -89,7 +89,7 @@ const w3cHtmlValidator = {
|
|
|
89
89
|
const maxLen = settings.maxMessageLen ?? undefined;
|
|
90
90
|
log(typeColor('HTML ' + type + ':'), message.message.substring(0, maxLen));
|
|
91
91
|
if (message.lastLine)
|
|
92
|
-
log(chalk.
|
|
92
|
+
log(chalk.white(location), chalk.magenta(lineText));
|
|
93
93
|
};
|
|
94
94
|
messages.forEach(logMessage);
|
|
95
95
|
return results;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//!
|
|
1
|
+
//! w3c-html-validator v1.0.0 ~~ 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.
|
|
23
|
+
version: '1.0.0',
|
|
24
24
|
validate(options) {
|
|
25
25
|
const defaults = {
|
|
26
26
|
checkUrl: 'https://validator.w3.org/nu/',
|
|
@@ -30,13 +30,13 @@ 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
|
-
const readFile = () => settings.filename ? fs_1.readFileSync(settings.filename, 'utf8') : null;
|
|
39
|
+
const readFile = () => settings.filename ? (0, fs_1.readFileSync)(settings.filename, 'utf8') : null;
|
|
40
40
|
const inputHtml = settings.html || readFile();
|
|
41
41
|
const makePostRequest = () => superagent_1.default.post(settings.checkUrl)
|
|
42
42
|
.set('Content-Type', 'text/html; encoding=utf-8')
|
|
@@ -90,7 +90,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
90
90
|
const title = settings.title ?? results.title;
|
|
91
91
|
const fail = 'fail (messages: ' + messages.length + ')';
|
|
92
92
|
const status = results.validates ? chalk_1.default.green('pass') : chalk_1.default.red.bold(fail);
|
|
93
|
-
fancy_log_1.default(chalk_1.default.
|
|
93
|
+
(0, fancy_log_1.default)(chalk_1.default.gray('w3c-html-validator'), chalk_1.default.blue.bold(title), status);
|
|
94
94
|
const typeColorMap = {
|
|
95
95
|
error: chalk_1.default.red.bold,
|
|
96
96
|
warning: chalk_1.default.yellow.bold,
|
|
@@ -102,9 +102,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
102
102
|
const location = `line ${message.lastLine}, column ${message.firstColumn}:`;
|
|
103
103
|
const lineText = message.extract?.replace(/\n/g, '\\n');
|
|
104
104
|
const maxLen = settings.maxMessageLen ?? undefined;
|
|
105
|
-
fancy_log_1.default(typeColor('HTML ' + type + ':'), message.message.substring(0, maxLen));
|
|
105
|
+
(0, fancy_log_1.default)(typeColor('HTML ' + type + ':'), message.message.substring(0, maxLen));
|
|
106
106
|
if (message.lastLine)
|
|
107
|
-
fancy_log_1.default(chalk_1.default.
|
|
107
|
+
(0, fancy_log_1.default)(chalk_1.default.white(location), chalk_1.default.magenta(lineText));
|
|
108
108
|
};
|
|
109
109
|
messages.forEach(logMessage);
|
|
110
110
|
return results;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w3c-html-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
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",
|
|
@@ -61,35 +61,39 @@
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
64
|
+
"step:01": "rimraf build dist **/.DS_Store",
|
|
65
|
+
"step:02": "jshint . --exclude node_modules,build,dist",
|
|
66
|
+
"step:03": "eslint --max-warnings 0 . --ext .ts",
|
|
67
|
+
"step:04": "tsc",
|
|
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",
|
|
70
|
+
"step:07": "add-dist-header build dist",
|
|
71
|
+
"pretest": "npm-run-all step:*",
|
|
72
|
+
"test": "mocha spec/*.spec.js --timeout 5000",
|
|
73
|
+
"examples": "node examples.js"
|
|
69
74
|
},
|
|
70
75
|
"dependencies": {
|
|
71
|
-
"chalk": "~
|
|
72
|
-
"fancy-log": "~
|
|
73
|
-
"glob": "~7.
|
|
74
|
-
"superagent": "~
|
|
76
|
+
"chalk": "~5.0",
|
|
77
|
+
"fancy-log": "~2.0",
|
|
78
|
+
"glob": "~7.2",
|
|
79
|
+
"superagent": "~7.0"
|
|
75
80
|
},
|
|
76
81
|
"devDependencies": {
|
|
77
82
|
"@types/fancy-log": "~1.3",
|
|
78
|
-
"@types/
|
|
83
|
+
"@types/glob": "~7.2",
|
|
84
|
+
"@types/node": "~17.0",
|
|
79
85
|
"@types/superagent": "~4.1",
|
|
80
|
-
"@typescript-eslint/eslint-plugin": "~
|
|
81
|
-
"@typescript-eslint/parser": "~
|
|
86
|
+
"@typescript-eslint/eslint-plugin": "~5.9",
|
|
87
|
+
"@typescript-eslint/parser": "~5.9",
|
|
88
|
+
"add-dist-header": "~0.1",
|
|
82
89
|
"assert-deep-strict-equal": "~0.0",
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"gulp-header": "~2.0",
|
|
86
|
-
"gulp-rename": "~2.0",
|
|
87
|
-
"gulp-replace": "~1.1",
|
|
88
|
-
"gulp-size": "~4.0",
|
|
90
|
+
"cpy-cli": "~3.1",
|
|
91
|
+
"eslint": "~8.6",
|
|
89
92
|
"jshint": "~2.13",
|
|
90
93
|
"merge-stream": "~2.0",
|
|
91
|
-
"mocha": "~9.
|
|
94
|
+
"mocha": "~9.1",
|
|
95
|
+
"npm-run-all2": "~5.0",
|
|
92
96
|
"rimraf": "~3.0",
|
|
93
|
-
"typescript": "~4.
|
|
97
|
+
"typescript": "~4.5"
|
|
94
98
|
}
|
|
95
99
|
}
|