Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

validate.presence

Daniel Gorman edited this page Sep 25, 2019 · 1 revision

The validate.presence Function

Function Group: Validation

validate.presence returns a given value if the value is present, or an error if the value is not present.

Syntax

validate.presence(arg1, arg2)

  • arg1 is the datum or a reference to the datum.
  • arg2 is the error message to return if arg1 evaluates to null.

Given the following data structure:

{
  "driver_ids":
  {
    "first": 999,
    "second": null
  }
}

If we want to perform an operation but aren't sure whether the value will exist, we can confirm that it does (or doesn't) with validate.presence:

validate.presence(driver_ids.first, "This error message won't be executed")

Will return 999.

validate.presence(driver_ids.second, "Value was null!")

Will return "Value was null!".

Clone this wiki locally