Skip to content

Latest commit

 

History

History
202 lines (167 loc) · 5.01 KB

BOOLEAN.md

File metadata and controls

202 lines (167 loc) · 5.01 KB

Boolean methods

  1. mustBe
  • Checks if the value is equal to the specified boolean value.
     mustBe(mustBeValue: boolean, message?: string)
  • Parameters:
    • mustBeValue: The value that the boolean must be equal to.
    • message (optional): Overrides the default error message.
  • Example:
     boolean().mustBe(true, "Value must be true")
  1. test
  • Allows you to define custom synchronous validation methods for the schema.
     test(method: TestMethodConfig<RuleBooleanMethod<Input, Form>>)
  • Parameters:
    • method: Configuration object containing the validation method and error message.
      • is: The validation method which returns a boolean indicating whether the value is valid.
      • message: Error message to be displayed when validation fails.
  • Example
     import { boolean } from '@resourge/schema';
    
     // Define an boolean schema
     boolean().test({
       is: (value) => value,
       message: "Value must be true"
     });
  1. asyncTest
  • Enables the definition of custom asynchronous validation methods for the schema.
     asyncTest(method: TestMethodConfig<AsyncRuleBooleanMethod<Input, Form>>)
  • Parameters:
    • method: Configuration object containing the asynchronous validation method and error message.
      • is: The asynchronous validation method which returns a promise resolving to a boolean indicating whether the value is valid.
      • message: Error message to be displayed when validation fails.
  • Example
     import { boolean } from '@resourge/schema';
    
     // Define an boolean schema
     boolean().asyncTest({
       is: async (value) => Promise.resolve(value),
       message: "Value must be true"
     });
  1. when
  • Facilitates conditional validation based on a specified condition.
     when(name: string, config: WhenConfig<S, Value, Form>)
     when(config: WhenConfig<S, Value, Form>)
  • Parameters:
    • name (optional): Name of the condition (if provided).
    • config: Configuration object defining the condition and corresponding actions.
      • is: The condition function which returns a boolean.
      • then: A callback function to be executed if the condition is true.
      • otherwise: A callback function to be executed if the condition is false.
  • Example
     import { boolean } from '@resourge/schema';
    
     // Define an boolean schema
     boolean().when({
       is: (value) => value,
       then: (schema) => schema.required(),
       otherwise: (schema) => schema.notOptional()
     });
  1. onlyOnTouch
  • Allows validation to occur only when a field is interacted with (touched).
     onlyOnTouch(onlyOnTouch?: (schema: this) => this)
  • Parameters:
    • onlyOnTouch (optional): A custom callback function to define validation behavior when validation occurs only on touch.
  • Example
     import { boolean } from '@resourge/schema';
    
     // Define an boolean schema
     boolean().onlyOnTouch();
  1. notOnlyOnTouch
  • Disables the validation to occur only on touch, allowing validation on any interaction.
     notOnlyOnTouch()
  • Example
     import { boolean } from '@resourge/schema';
    
     // Define an boolean schema
     boolean().notOnlyOnTouch();
  1. required
  • Makes a field mandatory for validation.
     required(message?: string)
  • Parameters:
    • message (optional): Custom error message to be displayed when the value is required but missing.
  • Example
     import { boolean } from '@resourge/schema';
    
     // Define an boolean schema
     boolean().required("Value is required");
  1. notRequired
  • Marks a field as optional for validation.
     notRequired()
  • Example
     import { boolean } from '@resourge/schema';
    
     // Define an boolean schema
     boolean().notRequired();
  1. optional
  • Allows a field to be optional during validation.
     optional()
  • Example
     import { boolean } from '@resourge/schema';
    
     // Define an boolean schema
     boolean().optional();;
  1. notOptional
  • Ensures that a field is not optional for validation.
     notOptional(message?: string)
  • Parameters:
    • message (optional): Custom error message to be displayed when the value is not optional but is missing.
  • Example
     import { boolean } from '@resourge/schema';
    
     // Define an boolean schema
     boolean().notOptional("Value is not optional");;
  1. nullable
  • Permits null values during validation.
     nullable()
  • Example
     import { boolean } from '@resourge/schema';
    
     // Define an boolean schema
     boolean().nullable();
  1. notNullable
  • Prohibits null values during validation.
     notNullable(message?: string)
  • Parameters:
    • message (optional): Custom error message to be displayed when the value is not nullable but is null.
  • Example
     import { boolean } from '@resourge/schema';
    
     // Define an boolean schema
     boolean().notNullable("Value cannot be null");;