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

strickland

v2.2.0

Published

Strickland is a JavaScript validation framework with a focus on extensibility and composition

Downloads

1,280

Readme

Readme

Strickland is a JavaScript validation framework with a focus on extensibility and composability. It is built with pure, universal JavaScript and while it works well with React, Redux, and other UI libraries, Strickland is not coupled to any other library or application type.

Strickland is a unique and robust approach to building validation into your application.

  • It is not a type system and it does not interfere with how you create and manage objects
  • Instead, validation rules are defined separately from the data
  • While Strickland can be used within the UI layer (including React components or Redux modules), it is not limited to use within UI
  • Universal applications can share validators across both client-side and server-side validation
  • With its extensibility and composability, Strickland supports complex scenarios in large line-of-business applications

Strickland focuses not on being a bloated collection of validators, but instead on enabling you to create your application's collection of validators and compose them together easily.

Separation of Concerns

In any validation implementation, there are three separate concerns that you must address, regardless of the libraries used.

  1. Validation Rules are the logic of how data is validated
  2. Validation Triggers are the events that trigger validation to occur at the field or form level
  3. Validation Results are presented to the user as the output of your validation rules

The most robust, flexible, and maintainable validation implementations keep these three concerns separated. Validation rules should not be coupled to the validation triggers or how the results will be presented. Validation triggers should not be coupled in any way to the validation rules or how the results will be presented. And the presentation of validation results should not be coupled to how validation was triggered or what the rules were.

With this separation of concerns in mind, Strickland strives to:

  1. Provide a flexible framework for authoring validation rules so that many different types of validation rules can be authored while remaining decoupled from validation triggers and how validation results are displayed
  2. Be completely uninvolved in validation triggers so that consuming applications can be built with any UI frameworks and without imposing any opinions on user interactions
  3. Provide a consistent structure for exposing validation results so that they can be consumed by applications consistently regardless of how many or what types of validation rules are present

Core Concepts

To address the core concepts above, there are three core concepts you need to know with Strickland:

  1. Validators are implementations of your validation rules
  2. Validation is the act of executing a validator against a value
  3. Validation Results are the output of validation for the given validator and value

Creating Validators

Strickland validators are pure functions that accept values and return validation results. Here is an extremely simple validator that validates that the value supplied is the letter 'A', returning the validation result as a boolean.

function letterA(value) {
    return (value === 'A');
}

Performing Validation

Strickland's default export is a validate function that accepts a validator function and the value to validate against the validator; it returns the validation result.

import validate from 'strickland';

function letterA(value) {
    return (value === 'A');
}

const result = validate(letterA, 'B');

Validation Results

Strickland normalizes validation results to always be objects with isValid and value properties.

If the validator returns a falsy value, then isValid will be false. If the validator returns true, then isValid will be true. If the validator returns an object, the truthiness of its isValid property will be used on the result's isValid property.

The value on the validation result will always be the value that was validated.

import validate from 'strickland';

function letterA(value) {
    // We can return a validation result as a boolean
    return (value === 'A');

    // Or as an object
    // return {
    //    isValid: (value === 'A')
    // };
}

const result = validate(letterA, 'B');

// Either way, the result will match:
//
// result = {
//     isValid: false,
//     value: 'B'
// }

Documentation

Detailed documentation is available at strickland.io.

License

MIT