📦
Schema
  • Getting Started
  • Documents
    • Basics
      • Extend
    • Any
      • Label
      • Default
      • Required
      • Pipe
      • Validate
    • Array
      • Length
      • Max
      • Min
      • Items
    • Boolean
    • Date
      • Max
      • Min
    • Number
      • Max
      • Min
      • Multiple
      • Integer
      • Port
      • Positive
      • Precision
    • Object
      • Length
      • Max
      • Min
      • Keys
    • String
      • Alphanum
      • Credit Card
      • Email
      • Enum
      • IP Address
      • Length
      • Max
      • Min
      • Numeral
      • Regex
      • Token
  • Source Code
Powered by GitBook
On this page
  • Make required
  • Override

Was this helpful?

  1. Documents
  2. Any

Required

Mark the value as required

Make required

Checks if the given value is not null or undefined

import Schema from "@rapidom/schema";

const Validator = Schema.number().required();
const Validator = Schema.number().required(true); // same result

// All these cases fail just because it's required
Validator.validate(); // defaults to the default value which is null by default!
Validator.validate(null);
Validator.validate(undefined);

Override

Change an already required validator into a non-required one

import Schema from "@rapidom/schema";

let Validator = Schema.number().required();

Validator = Validator.required(false); // make it not required again

// All these cases will succeed and return null
// Just because it's not required anymore
Validator.validate();
Validator.validate(null);
Validator.validate(undefined);
PreviousDefaultNextPipe

Last updated 3 years ago

Was this helpful?