Is currency code¶
isCurrencyCode validates that a value is an ISO‑4217 currency code.
It enforces strict structural and format requirements: the value must be a string, and it must match the canonical three‑letter uppercase pattern. Any non‑string value or incorrectly formatted code results in a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.validate('string.currencyCode')
And internally:
export const isCurrencyCode: ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
type.not.valid |
Value is not a string. |
string.not.currency-code |
String does not match ISO‑4217 three‑letter format. |
Design rationale¶
- Enforces strict ISO‑4217 formatting: exactly three uppercase letters.
- Rejects non‑string values early with a structural‑type diagnostic.
- Avoids normalization or case‑folding — contributors must provide canonical codes.
- Emits exactly one event per failure for clarity and composability.
- Pure, total, async‑compatible, and returns a readonly array of
JaneEventobjects. - Preserves the provided path and supports pipeline‑level
userMessageoverrides.
Invoke¶
isCurrencyCode 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 string does not match
/^[A-Z]{3}$/, emitsstring.not.currency-code. - Otherwise, returns an empty result set.
Examples¶
Valid — canonical ISO‑4217 codes¶
await isCurrencyCode("USD", "$");
// → []
await isCurrencyCode("EUR", "$");
// → []
Invalid — non‑string values¶
await isCurrencyCode(123, "$");
// → [
// JaneEvent{
// kind: "error",
// code: "type.not.valid",
// path: "$",
// ...
// }
// ]
Invalid — incorrect format¶
await isCurrencyCode("usd", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "string.not.currency-code",
// path: "$",
// ...
// }
// ]
await isCurrencyCode("US", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "string.not.currency-code",
// path: "$",
// ...
// }
// ]