html-validator
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -6,2 +6,3 @@ 'use strict' | ||
const setupOptions = require('./lib/setup-options') | ||
const filterData = require('./lib/filter-data') | ||
@@ -35,2 +36,3 @@ module.exports = (options, callback) => { | ||
const reqOpts = setupOptions(options) | ||
const ignore = options.ignore | ||
@@ -53,4 +55,8 @@ request(reqOpts, (error, response, result) => { | ||
const data = options.format === 'json' ? JSON.parse(result) : result | ||
var data = options.format === 'json' && !ignore ? JSON.parse(result) : result | ||
if (ignore) { | ||
data = filterData(data, ignore) | ||
} | ||
if (callback) { | ||
@@ -57,0 +63,0 @@ return callback(null, data) |
{ | ||
"name": "html-validator", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Validate html using validator.w3.org/nu", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -41,4 +41,6 @@ [](https://travis-ci.org/zrrrzzt/html-validator) | ||
**url** The url to the page you want to validate. | ||
**url**/**data** The url to the page you want to validate or the data you want validated. | ||
**ignore** String or array of strings you want the checker to remove in the response | ||
#### Promise | ||
@@ -173,3 +175,47 @@ | ||
**ignore** String or array of strings you want the checker to remove in the response. Requires format = text | ||
### Promise | ||
```JavaScript | ||
const validator = require('html-validator') | ||
const options = { | ||
url: 'http://url-to-validate.com', | ||
format: 'text', | ||
ignore: 'Error: Stray end tag “div”.' | ||
} | ||
validator(options) | ||
.then((data) => { | ||
console.log(data) | ||
}) | ||
.catch((error) => { | ||
console.error(error) | ||
}) | ||
``` | ||
#### Callback | ||
```JavaScript | ||
const validator = require('html-validator') | ||
const options = { | ||
url: 'http://url-to-validate.com', | ||
format: 'text', | ||
ignore: 'Error: Stray end tag “div”.' | ||
} | ||
validator(options, (error, data) => { | ||
if (error) { | ||
console.error(error) | ||
} | ||
console.log(data) | ||
}) | ||
``` | ||
## Related | ||
- [html-validator-cli](https://github.com/zrrrzzt/html-validator-cli) CLI for this module | ||
- [html-validator-cli](https://github.com/zrrrzzt/html-validator-cli) CLI for this module | ||
## License | ||
[MIT](LICENSE) |
@@ -120,1 +120,17 @@ 'use strict' | ||
}) | ||
tap.test('Should get 0 error messages from invalid.html if ignored', (test) => { | ||
const options = { | ||
format: 'text', | ||
data: fs.readFileSync('test/data/invalid.html'), | ||
ignore: 'Error: Stray end tag “div”.' | ||
} | ||
validator(options) | ||
.then((data) => { | ||
tap.equal(false, /Error/.test(data), 'No errors found') | ||
test.done() | ||
}) | ||
.catch((error) => { | ||
throw error | ||
}) | ||
}) |
@@ -100,1 +100,16 @@ 'use strict' | ||
}) | ||
tap.test('Should get 0 error messages from invalid.html if ignored', (test) => { | ||
const options = { | ||
format: 'text', | ||
data: fs.readFileSync('test/data/invalid.html'), | ||
ignore: 'Error: Stray end tag “div”.' | ||
} | ||
validator(options, (error, data) => { | ||
if (error) { | ||
throw error | ||
} | ||
tap.equal(false, /Error/.test(data), 'No errors found') | ||
test.done() | ||
}) | ||
}) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
23172
18
407
219
0
5