Giter VIP home page Giter VIP logo

html-validator's Introduction

Build Status Coverage Status js-standard-style

html-validator

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

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.

Installation

From npm

$ npm install html-validator

From GitHub

$ git clone [email protected]:zrrrzzt/html-validator.git

Then cd into directory and run the setup script

$ npm run setup

Usage

Create an options object.

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

validator You can override the default validator as long as it exposes the same REST interface.

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

const validator = require('html-validator')
const options = {
 url: 'http://url-to-validate.com',
 format: 'text'
}

validator(options)
  .then((data) => {
    console.log(data)
  })
  .catch((error) => {
    console.error(error)
  })

Callback

const validator = require('html-validator')
const options = {
 url: 'http://url-to-validate.com',
 format: 'text'
}

validator(options, (error, data) => {
  if (error) {
    console.error(error)
  }
  console.log(data)
})

data The html you want to validate

Promise

const validator = require('html-validator')
const fs = require('fs')
var options = {
  format: 'text'
}

fs.readFile( 'file-to-validate.html', 'utf8', (err, html) => {
  if (err) {
    throw err;
  }
  
  options.data = html

  validator(options)
    .then((data) => {
      console.log(data)
    })
    .catch((error) => {
      console.error(error)
    })
})

Callback

const validator = require('html-validator')
const fs = require('fs')
var options = {
  format: 'text'
}

fs.readFile( 'file-to-validate.html', 'utf8', (err, html) => {
  if (err) {
    throw err;
  }
  
  options.data = html

  validator(options, (error, data) => {
    if (error) {
      console.error(error)
    }

    console.log(data)
  })
})

validator You can override the default validator as long as it exposes the same REST interface.

Promise

const validator = require('html-validator')
const options = {
  url: 'http://url-to-validate.com',
  validator: 'http://html5.validator.nu',
  format: 'text'
};

validator(options)
  .then((data) => {
    console.log(data)
  })
  .catch((error) => {
    console.error(error)
  })

Callback

const validator = require('html-validator')
const options = {
  url: 'http://url-to-validate.com',
  validator: 'http://html5.validator.nu',
  format: 'text'
};

validator(options, (error, data) => {
  if (error) {
    console.error(error)
  }

  console.log(data)
})

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

Promise

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

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)
})

headers Object of headers to pass in with the url request

Promise

const validator = require('html-validator')
const options = {
 url: 'http://url-to-validate.com',
 headers: {foo:"bar"}
}

validator(options)
  .then((data) => {
    console.log(data)
  })
  .catch((error) => {
    console.error(error)
  })

Callback

const validator = require('html-validator')
const options = {
 url: 'http://url-to-validate.com',
 headers: {foo:bar}
}

validator(options, (error, data) => {
  if (error) {
    console.error(error)
  }
  console.log(data)
})

Related

License

MIT

html-validator's People

Contributors

danpaz avatar davidtheclark avatar greenkeeper[bot] avatar greenkeeperio-bot avatar renovate-bot avatar zrrrzzt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.