Strickland
  • Readme
  • Introduction
    • Validators
    • Validation
    • Validation Results
  • Extensibility
    • Validator Factories
    • Validation Context
    • Validation Result Props
    • Extensibility Pattern
    • formatResult
  • Built-In Validators
    • required
    • compare
    • min
    • max
    • range
    • minLength
    • maxLength
    • length
  • Composition
    • Arrays of Validators
      • every
      • all
      • some
    • Validating Array Elements
      • arrayElements
    • Validating Objects
      • objectProps
      • Advanced Object Validation
      • Nested Objects
      • Arrays of Objects
    • Composition Conventions
    • Composition and formatResult
  • Async Validation
    • Resolving Async Validation
    • Deferred Async Validation
    • Async Validator Arrays and Objects
    • Two-Stage Sync/Async Validation
    • Race Conditions
    • Automatic Race Condition Handling
    • Async Validation and formatResult
  • Form Validation
    • form
    • Async Form Validation
    • validateFields
    • emptyResults
    • updateFieldResults
  • Inspiration
  • Design Goals
  • Wrap-Up
  • Change Log
  • NPM
  • GitHub
Powered by GitBook
On this page

Was this helpful?

  1. Introduction

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 a truthy value, 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'
// }
PreviousValidationNextExtensibility

Last updated 4 years ago

Was this helpful?