Skip to content

No repeat space

noRepeatSpace validates that a string does not contain repeated consecutive space characters.

It enforces strict structural string validation and rejects any non-string value or string containing two or more consecutive spaces. If the value is not a string or contains repeated spaces, the rule emits a single validation event. Otherwise, it produces no validation output.

Signature

Through the API:

.noRepeatSpace()

And internally:

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

Events

Event code Description
type.not.valid Value is not structurally a string
string.has.repeating-whitespace String contains repeated consecutive spaces

Design rationale

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

noRepeatSpace 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 contains repeated spaces, emits string.has.repeating-whitespace.
  • If the value is a string with no repeated spaces → returns an empty result set.

Examples

Valid string without repeated spaces

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

String with repeated spaces

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

Non-string value

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