npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

html-validator

v6.0.1

Published

Validate html using validator.w3.org/nu og html-validate

Downloads

90,194

Readme

js-standard-style

html-validator

A Node.js module for validating html using validator.w3.org/nu or html-validate

Requires Node >= 14.18.1

Webpack

If you are using Webpack you might have som problems due to html-validate. You can stick to the 5.0.3 version of this module or try some of the workarounds described here

Module

Supports the following modes from Validator.nu Web Service Interface

  • Document URL as a GET parameter; the service retrieves the document by URL over HTTP or HTTPS.
  • Document POSTed as the HTTP entity body; parameters in query string as with GET.

From html-validate it will only validate against the WHATWG standards.

Installation

$ npm i html-validator

Usage

Create an options object.

format This is the formatting of the returned data. It supports json (default), html, xhtml, xml, gnu and text for W3C and json for WHATWG.

validator You can override the default validator (W3C) as long as it exposes the same REST interface. To use WHATWG just pass WHATWG as a string

url/data The url to the page you want to validate or the data you want validated.

ignore String or array of strings or rules (when using WHATWG) you want the checker to remove in the response

isLocal Set this to true if you want to validate local urls

isFragment Set this to true if your data input is not a complete document

W3C (default)

(async () => {
  const validator = require('html-validator')
  const options = {
    url: 'http://url-to-validate.com',
    format: 'text'
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

data The html you want to validate

(async () => {
  const validator = require('html-validator')
  const { readFileSync } = require('fs')
  const options = {
    url: 'http://url-to-validate.com',
    format: 'text',
    data: readFileSync('file-to-validate.html', 'utf8')
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

validator You can override the default validator as long as it exposes the same REST interface. Or use the WHATWG option for validating your files locally

(async () => {
  const validator = require('html-validator')
  const options = {
    url: 'http://url-to-validate.com',
    validator: 'http://html5.validator.nu',
    format: 'text'
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()
(async () => {
  const validator = require('html-validator')
  const options = {
    url: 'http://url-to-validate.com',
    validator: 'WHATWG',
    format: 'text'
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

or run the w3c validator locally with docker $ docker run -d -p 8888:8888 validator/validator and

(async () => {
  const validator = require('html-validator')
  const options = {
    url: 'http://url-to-validate.com',
    validator: 'http://localhost:8888',
    format: 'text'
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

ignore String or array of strings you want the checker to remove in the response. Requires format = text

(async () => {
  const validator = require('html-validator')
  const options = {
    url: 'http://url-to-validate.com',
    format: 'text',
    ignore: 'Error: Stray end tag “div”.'
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

headers Object of headers to pass in with the url request

(async () => {
  const validator = require('html-validator')
  const options = {
    url: 'http://url-to-validate.com',
    format: 'text',
    headers: {foo:"bar"}
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

isLocal Set this to true if you want to validate local urls. Will lookup page and send data to validator

(async () => {
  const validator = require('html-validator')
  const options = {
    url: 'http://url-to-validate.com',
    format: 'text',
    isLocal: true
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

isFragment Set this to true if you want to validate something that is not a complete document

(async () => {
  const validator = require('html-validator')
  const options = {
    data: '<p>This is a fragment</p>',
    isFragment: true
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

WHATWG

Using this option will validate your files locally and will probably speed up your tests in addition to not sending data over the wire for validation.

You can follow all the examples from W3C as long as you changes the options validator property to WHATWG

(async () => {
  const validator = require('html-validator')
  const options = {
    validator: 'WHATWG',
    data: '<p>This is a fragment</p>',
    isFragment: true
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

Related

License

MIT