Skip to content

Is null or undefined

isNullOrUndefined validates that a value is either null or undefined.

It performs a nullish check and rejects any value that is neither null nor undefined. If the value is not nullish, the rule emits a single validation event. Otherwise, it produces no validation output.

Signature

Through the API:

.isNullOrUndefined()

And internally:

export const isNullOrUndefined: ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>

Events

Event code Description
value.not.null-or-undefined Value is neither null nor undefined

Design rationale

  • Provides a strict, predictable nullish value validation.
  • Accepts both null and undefined as valid.
  • Rejects empty strings, zero, and other falsy values.
  • Never coerces or normalizes — validation is explicit and opt-in.
  • Emits exactly one event per failure for clarity and composability.
  • Async-compatible and returns a readonly array of JaneEvent objects.

Invoke

isNullOrUndefined runs only when explicitly included in a boundary or pipeline. It does not run automatically.

The rule activates when:

  • The value is any JavaScript value.
  • If the value is neither null nor undefined, emits value.not.null-or-undefined.
  • If the value is null or undefined → returns an empty result set.

Examples

Valid null value

await isNullOrUndefined(null, "$");
// → []

Valid undefined value

await isNullOrUndefined(undefined, "$");
// → []

Non-nullish values

await isNullOrUndefined("", "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "value.not.null-or-undefined",
//       path: "$",
//       ...
//     }
//   ]