Skip to content

Is printable

isPrintable validates that a string contains only printable ASCII characters (code points 0x20–0x7E).

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

Signature

Through the API:

.isPrintable()

And internally:

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

Events

Event code Description
string.not.string Value is not structurally a string
string.not.printable String contains non-printable ASCII characters

Design rationale

  • Provides a strict, predictable printable ASCII character set validation.
  • Rejects non-string values with a clear structural-type diagnostic.
  • Uses well-defined printable ASCII code point range for consistency and predictability.
  • 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

isPrintable 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 a string but contains non-printable characters, emits string.not.printable.
  • If the value is a string containing only printable ASCII characters → returns an empty result set.

Examples

Valid printable string

await isPrintable("Hello World!", "$");
// → []

String with non-printable characters

await isPrintable("Hello\x00World", "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "string.not.printable",
//       path: "$",
//       ...
//     }
//   ]

Non-string value

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