Chars equal¶
charsEqual validates that a string has exactly a specified number of characters.
It enforces strict structural string validation and rejects any non-string value or string whose length does not match the required length. If the value is not a string or has the wrong length, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.charsEqual(exact: number)
And internally:
export const charsEqual = (exact: number): ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
type.not.valid |
Value is not structurally a string |
string.has.invalid-length |
String length does not match required length |
Design rationale¶
- Provides a strict, predictable exact length 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
JaneEventobjects.
Invoke¶
charsEqual 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 has wrong length, emits
string.has.invalid-length. - If the value is a string with exactly the required length → returns an empty result set.
Examples¶
Valid string with exact length¶
await charsEqual(5)("hello", "$");
// → []
String with wrong length¶
await charsEqual(5)("hi", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "string.has.invalid-length",
// path: "$",
// ...
// }
// ]
Non-string value¶
await charsEqual(3)(42, "$");
// → [
// JaneEvent{
// kind: "error",
// code: "type.not.valid",
// path: "$",
// ...
// }
// ]