Introducing Whitelister

Open source software is at the heart of all that we do here at Spire Labs. We believe any opportunity to give back to the community is an opportunity worth taking. Today, we would like to introduce Whitelister — a simple, dependency-free filtering and validation tool for Node.js.

The tool has served us well, in production, for the last 2 years. It has grown to become flexible and powerful without losing its simplicity. We started using Whitelister to filter and validate user input, but have recently begun to use it as a way to whitelist output data. Once we moved the main function into a separate module, it became clear that open sourcing Whitelister as an NPM package would be so easy, we had to do it.

If you want to try Whitelister without installing it, you can do so via runkit.

Getting Started

Install Whitelister using either NPM or yarn.

$ npm install whitelister --save
// or
$ yarn add whitelister@latest

Require the package into your project.

const whitelister = require('whitelister');

Next, define a set of rules to filter and validate against.

const rules = {
email: { type: 'email', required: true },
password: { type: 'string', required: true },
};

To use Whitelister’s default Promise interface, use it as a function directly.

const params = {
email: 'david@spirelabs.co',
password: 'P@$$W0rD',
username: 'david',
};

whitelister(rules, params).then((filteredParams) => {
console.log(filteredParams);
// => { email: "david@spirelabs.co", password: "p@$$W0rD" }
});

Whitelister also offers a synchronous interface.

const params = {
email: 'david@spirelabs.co',
password: 'P@$$W0rD',
username: 'david',
};

const filteredParams = whitelister.sync(rules, params);
// => { email: "david@spirelabs.co", password: "p@$$W0rD" }

Thank You

All of Whitelister’s code is hosted on GitHub along with its documentation.

Again, we are all so grateful to share a piece of our work with the community and hope you can find value in a tool that has served us so well.

with ❤️, from Chattanooga
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.