forked from thomasdavis/w3cjs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexamples.js
22 lines (18 loc) · 953 Bytes
/
examples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env node
////////////////////////
// W3C HTML Validator //
// Examples //
////////////////////////
// Command to run:
// $ node examples.js
import { w3cHtmlValidator } from './dist/w3c-html-validator.js';
// Formatted output
const options = { continueOnFail: true, maxMessageLen: 80 };
const customReporter = (results) => w3cHtmlValidator.reporter(results, options);
w3cHtmlValidator.validate({ website: 'https://pretty-print-json.js.org/' }).then(w3cHtmlValidator.reporter);
w3cHtmlValidator.validate({ filename: 'spec/html/valid.html' }).then(w3cHtmlValidator.reporter);
w3cHtmlValidator.validate({ filename: 'spec/html/invalid.html' }).then(customReporter);
// JSON output
const sleep = (data) => new Promise(resolve => setTimeout(() => resolve(data), 2000));
const log = (results) => console.log('\nValidatorResults:', results);
w3cHtmlValidator.validate({ filename: 'spec/html/invalid.html' }).then(sleep).then(log);