Skip to content

Is ascii

isAscii validates that a string contains only ASCII characters (code points 0x00–0x7F).

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

Signature

Through the API:

.isAscii()

And internally:

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

Events

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

Design rationale

  • Provides a strict, predictable ASCII character set validation.
  • Rejects non-string values with a clear structural-type diagnostic.
  • Uses well-defined 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

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

Examples

Valid ASCII string

await isAscii("Hello123", "$");
// → []

String with non-ASCII characters

await isAscii("café", "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "string.not.ascii",
//       path: "$",
//       ...
//     }
//   ]

Non-string value

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