Skip to content

Non-empty

nonEmpty validates that a string contains at least one character.

It enforces strict structural string validation and rejects any non-string value or empty string. If the value is not a string or is empty, the rule emits a single validation event. Otherwise, it produces no validation output.

Signature

Through the API:

.nonEmpty()

And internally:

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

Events

Event code Description
string.not.string Value is not structurally a string
string.is.empty String contains no characters

Design rationale

  • Provides a strict, predictable non-empty string validation.
  • Rejects non-string values with a clear structural-type diagnostic.
  • 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

nonEmpty 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 a string, emits string.not.string.
  • If the value is an empty string, emits string.is.empty.
  • If the value is a non-empty string → returns an empty result set.

Examples

Valid non-empty string

await nonEmpty("hello", "$");
// → []

Empty string

await nonEmpty("", "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "string.is.empty",
//       path: "$",
//       ...
//     }
//   ]

Non-string value

await nonEmpty(42, "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "string.not.string",
//       path: "$",
//       ...
//     }
//   ]