Predicate function - Validation

The validation functions are used for conditions and rule-based validation logic.

  • These predicates support conditional validation logic rather than format or type checks.

  • Inputs may be of any type , unless otherwise specified.

  • Null , undefined , empty strings, empty arrays, and empty objects are treated explicitly and consistently.

  • Validation predicates are commonly used in forms, workflow rules, and business logic.

Function

Description

Example

IsRequired(value) Returns true if the value is present and not empty/null.
  • "text" is true

  • 0 is true

  • false is true

  • "" is false

  • " " is false

  • null is false

  • [] is false

IsOptional(value) Returns true if a value is absent, null, undefined, or empty.
  • null is true

  • "" is true

  • " " is true

  • [] is true

  • {} is true

  • "data" is false

  • 0 is false

  • false is false

IsValidWhen(value, condition) Returns true if:
  • the condition is false (validation does not apply), or

  • the condition is true and the value satisfies IsRequired.

  • IsValidWhen("value", true) is true

  • IsValidWhen(null, false) is true

  • IsValidWhen(" ", false) is true

  • IsValidWhen(null, true) is false

  • IsValidWhen(" ", true) is false

IsInvalidWhen(value, condition) Returns true if:
  • the condition is false (validation does not apply), or

  • the condition is true and the value is empty or absent.

  • IsInvalidWhen(null, true) is true

  • IsInvalidWhen(" ", true) is true

  • IsInvalidWhen("abc", true) is false

  • IsInvalidWhen(123, true) is false