Skip to content

No empty string items

noEmptyStringItems validates that an array does not contain any empty string ("") items.

It performs a strict structural array check and rejects any non‑array value. If the value is an array and contains at least one empty string, the rule emits a single validation event. Otherwise, it produces no validation output.

Signature

Through the API:

.noEmptyStrings();

And internally:

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

Events

Event code Description
array.not.array Value is not structurally an array.
array.has.empty-strings Array contains one or more empty string items.

Design rationale

  • Enforces strict, predictable validation that disallows empty string entries.
  • Rejects non‑array values with a structural‑type diagnostic.
  • Uses direct equality (item === "") for clarity and zero ambiguity.
  • Emits exactly one event per failure for clarity and composability.
  • Never coerces, normalizes, or transforms — validation is explicit and opt‑in.
  • Async‑compatible and returns a readonly array of JaneEvent objects.

Invoke

noEmptyStringItems 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 not an array, emits array.not.array.
  • If the value is an array and contains at least one empty string, emits array.has.empty-strings.
  • Otherwise, returns an empty result set.

Examples

Valid — no empty strings

await noEmptyStringItems(["a", "b", "c"], "$");
// → []

Invalid — contains empty string

await noEmptyStringItems(["a", "", "c"], "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "array.has.empty-strings",
//       path: "$",
//       ...
//     }
//   ]

Non‑array value

await noEmptyStringItems("not-an-array", "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "array.not.array",
//       path: "$",
//       ...
//     }
//   ]