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

valimate

v3.0.2

Published

Automated HTML validation tool

Downloads

44

Readme

Valimate

Build status Coverage Status npm version

Valimate is a configurable command line interface for validating local and remote websites against the Nu HTML Checker. It can be easily integrated with continuous integration pipelines and regression test suites.

Requires Node.js 10 or greater

Installing

npm i --save-dev valimate

Configuration

Valimate is configured on a per-project basis via the valimate.json file. This must reside in the root directory of your project. A simple configuration might look like this:

{
  "urls": [
    "http://jamesswright.co.uk/",
    "http://jamesswright.co.uk/about-me",
    "http://jamesswright.co.uk/skills"
  ]
}

To validate these URLs, run npx valimate in your terminal or valimate within the context of an npm script. Valimate will read the config; each URL is requested via HTTP GET, and the returned markup is sent to the Nu validator.

All of the configuration options are listed on the valimate.json wiki page.

Running with another configuration file

Run npx valimate file.json in your terminal or valimate file.json within the context of an npm script.

Running against a local app server

In a continuous integration scenario, it could be ideal validate your app server with the latest code changes. If this server is developed in Node.js, then you can use the Valimate Notifier module to defer the execution of tests until the server has started up and is ready to serve HTML.

In the valimate.json file, set the localAppServer to point to your server's entry script. You can also use the env property to pass environment variables to the process as key-value pairs:

{
  "localAppServer": {
    "entryPoint": "app.js",

    "env": {
      "TEST": "true"
    }
  },

  "urls": [
    "http://localhost:8081/"
  ]
}

Then use the Valimate Notifier module to notify Valimate when the server is ready to be validated. The module exports a fuction which accepts one argument; a truthy value suggests that start up was successful, whereas a falsy value suggests failure, causing Valimate to exit:

'use strict';

const http = require('http');
const notifyValimate = require('valimate-notifier');
const dataService = require('./services/myDataService');
const htmlBuilder = require('./view/htmlBuilder');

const PORT = 8081;

dataService.someAsyncOperation().then(data => {
  http.createServer((req, res) => {
    res.end(htmlBuilder(data), 'utf-8');
  }).listen(PORT, () => {
    notifyValimate(true);
  });
}).catch(e => notifyValimate(false));

Upon running the valimate CLI, your app server will be started as a child process, and killed when testing is complete.

If your app server has not been started by Valimate (e.g. running in production), then this method will do nothing.

Programmatic Use

Valimate can also be imported into your Node.js scripts as a CommonJS module. It exposes the validate method, which takes the config as a parameter of the Object type. This returns a Promise which resolves once the URLs have been validated. A Boolean is passed through the chain that will be true if the markup is invalid, or false if it is valid.

'use strict';

const valimate = require('valimate');

const config = {
  urls: [
    'http://jamesswright.co.uk/',
    'http://jamesswright.co.uk/about-me',
    'http://jamesswright.co.uk/skills'
  ]
};

/* protip: ~ = bitwise NOT - can use this twice to doubly
 * invert the bits to coerce a bool to 1 or 0 */
valimate.validate(config)
  .then(isInvalid => process.exit(~~isInvalid));

Using Valimate programmatically will still print results as if the library had been invoked via the CLI; this capability is simply a means of convenience; this can be useful when there are many asynchronous prerequisites involved. In the next major release, however, this may directly expose validation results.

Contributing

See the Contributing wiki page.