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

iq-validator

v1.0.0

Published

An intelligent string validator with configurable sanitisation options.

Downloads

8

Readme

iq-validator Build Status

An intelligent string validator with built-in configurable sanitisation capabilities.

Installation

npm install iq-validator

Usage

This demonstrate a basic usage of IqValidator.

import IqValidator from './IqValidator';

const sanitiseRules = [{
  regex: 'wrong',
  regexFlags: 'g',
  sanitiseFunction: str => str.replace('wrong', 'right'),
}];

const iqValidator = new IqValidator(new RegExp('right', 'g'), sanitiseRules);
const sanitised = iqValidator.sanitise('I feel so wrong!');
console.log(sanitised); // I feel so right!

Further information

The main purpose of IqValidator is to provide an easy and configurable way to sanitise large string datasets (for example coming from different databases or from un-validated spreadsheet exports).

It allows to specifiy a main regular expression which is used to determine if a specific string is valid or it needs sanitisation. In the second case, the user can specify an array of sanitisation rules each of them defined in form of javascript objects.

A rule is composed by a regex plus some optional regex flags (see RegExp javascript object docs) and a function which has the purpose of perfom some kind of string maniupulation as an attempt to sanitise (reformat) the invalid string.

When a string is passed to the sanitise method and is evaluated to invalid, the algorithm will loop through the array of possible sanitisation rules and check if the invalid string matches any of the defined sanitisation rules. At this point 3 scenarios can happen:

  1. One matching sanitisation rule found: In this case, the sanitisation function is invoked passing the invalid string as parameter. The function is expected to return a string which passes the main regular expression
  2. More than one matching sanitisation rules found. This shouldn't happen, in this case only the first matching sanitisation function is run.
  3. No matching sanitisation rule found: In this case null is returned