Socket
Book a DemoInstallSign in
Socket

strickland

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strickland

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

2.0.2
Source
npmnpm
Version published
Weekly downloads
348
14.1%
Maintainers
1
Weekly downloads
 
Created
Source

Strickland logo

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.

Core Concepts

There are three core concepts you need to know with Strickland:

  • Validators are implementations of your validation rules
  • Validation is the act of executing a validator against a value
  • 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

License

MIT

Keywords

validation

FAQs

Package last updated on 12 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.