Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

w3c-validate

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

w3c-validate

A node.js library for testing web responses against the w3c html validator. Inspired by [w3cjs](https://github.com/thomasdavis/w3cjs), but based purely on buffers.

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22
increased by4.76%
Maintainers
2
Weekly downloads
 
Created
Source

w3c-validate

A node.js library for testing web responses against the w3c html validator. Inspired by w3cjs, but based purely on buffers.

Use with your tests.

Build Status

Installation

npm install w3c-validate

Usage

var w3c = require('w3c-validate').createValidator();

w3c.validate('<html> ... </html>', function (err) {
  if (err) {
    console.error(err); // error includes [{message, context}] to help understand validation errors
  } else {
    console.log('Valid! Hurray!');
  }
});

Example async testing with Mocha

var request = require('supertest')
  , express = require('express')
  , w3c     = require('w3c-validate').createValidator();

var app = express();

app.get('/page', function(req, res){
  res.send(200,
    '<!DOCTYPE html>' +
    '<html lang="en">' +
    '<head><title>Hello</title></head>' +
    '<body>World</body>' +
    '</html>');
});

describe('html validation', function(){
  it('page should have no html errors', function(done){
    request(app)
      .get('/page')
      .expect(200)
      .end(function(err, res){
        if (err) return done(err);
        w3c.validate(res.text, done);
      });
  })
})

Ignoring errors

Sometimes, you'll have W3C Validation errors that you just want to ignore. Once you've identified the exact error message, you can pass that to the factory method. The validator will ignore these.

var w3c = require('w3c-validate').createValidator([
  'Attribute xmlns:fb not allowed here.'
]);

Running Tests

To run the test suite first invoke the following command within the repo, installing the development dependencies:

npm install

then run the tests:

npm test

Keywords

FAQs

Package last updated on 25 Sep 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc