Ends with¶
endsWith validates that a string ends with a specified suffix.
It enforces strict structural string validation and rejects any non-string value or string that does not end with the required suffix. If the value is not a string or does not end with the suffix, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.endsWith(suffix: string)
And internally:
export const endsWith = (suffix: string): ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
string.not.string |
Value is not structurally a string |
string.must.end-with |
String does not end with the required suffix |
Design rationale¶
- Provides a strict, predictable string suffix 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¶
endsWith 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 does not end with the suffix, emits
string.must.end-with. - If the value is a string that ends with the suffix → returns an empty result set.
Examples¶
Valid string with correct suffix¶
await endsWith(".com")("example.com", "$");
// → []
String with wrong suffix¶
await endsWith(".com")("example.org", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "string.must.end-with",
// path: "$",
// ...
// }
// ]
Non-string value¶
await endsWith(".txt")(42, "$");
// → [
// JaneEvent{
// kind: "error",
// code: "string.not.string",
// path: "$",
// ...
// }
// ]