Introducing Whitelister

David Hunt
Sep 20, 2017 · 2 min read
Image for post
Image for post

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

$ 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

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

Spire Labs

We build digital products that are good for people.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store