Skip to content

No trail space

noTrailSpace validates that a string does not end with whitespace.

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

Signature

Through the API:

.noTrailSpace()

And internally:

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

Events

Event code Description
type.not.valid Value is not structurally a string
string.has.trailing-whitespace String ends with whitespace

Design rationale

  • Provides a strict, predictable trailing whitespace 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

noTrailSpace 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 type.not.valid.
  • If the value is a string but ends with whitespace, emits string.has.trailing-whitespace.
  • If the value is a string that doesn't end with whitespace → returns an empty result set.

Examples

Valid string without trailing whitespace

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

String with trailing spaces

await noTrailSpace("hello  ", "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "string.has.trailing-whitespace",
//       path: "$",
//       ...
//     }
//   ]

Non-string value

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