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

defender

v0.1.1

Published

Defending inputs across the land.

Downloads

11

Readme

Defender

Defending inputs across the land.


Demo

Example of sort code validation in different guises using defender


Soothsayer

The Soothsayer is interlinked to the Fortune teller, but the basic idea is that you create a Soothsayer and give it a pattern that can be parsed and replaced by other things (RegExp, DOM elements).

The Soothsayer is not restricted by the bounds of the validator, just what you pass in for the look up of the pattern. If nothing is found an error is thrown.

To help with this we have Runes, which make it easier to work with Regular Expressions.


Example

The following example creates a Soothsayer and generates a possible future of regular expressions.

var pattern = IO(function() {
  return '##-##-##';
});
var sayer = soothsayer({
    '#': /^[0-9]/,
    '-': /^-/
})(pattern);

Guardian

The Guardians job in the flow is to remove any items from the input that you don't want to be validated by the Defender. In turn guarding the Defender.

It's a simple premise of using a regular expression to attempt to normalise the user input as much as possible, such as trimming the white space front and back or removing comments.


Example

The following example creates a Guardian which will guard against white space.

var guard = guardian(/^\s/);

Defender

The Defenders job is go through the Soothsayers runes and check the input against those runes. The result is either a failure or a success.

If the result is a failure a stack trace of where the input failed is passed back along with the position. This should make it easier to see what failed and where.


Example

The following example creates a Defender that when called uses the Guardian to guard the input.

var defend = defender(sayer);
defend(guard(io));

Fortune Teller

The Fortune Teller job is to decipher what the input field could possibly look like on key down, before the text has been entered. From there it should be possible to pipe this into the Defenders to then work out if a input is permitted.

The role of a Fortune Teller is highly specialized and because of this a lot more information is required to do the job at hand.


Example

The following uses a value of the current input field, it then grabs what the event is along with any key information (unicode characters etc...) and then finally the selection upon where the new character needs to be added, removed etc.

fortune(value)(fromEvent(e), selection);