Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 3x 22x 29x 7x 1x 8x 9x 15x 3x | import * as v from "valibot";
import { parseDecimal } from "../utils/interest";
type InterestFormIssue = "principal" | "from" | "to" | "order";
export const interestFormSchema = (message: (issue: InterestFormIssue) => string) =>
v.config(
v.pipe(
v.object({
principal: v.pipe(
v.string(() => message("principal")),
v.transform((text) => parseDecimal(text, { grouping: true })),
v.number(() => message("principal")),
v.minValue(0.01, () => message("principal")),
),
rate: v.picklist(["legal", "judicial"]),
from: v.pipe(
v.string(),
v.isoDate(() => message("from")),
),
to: v.pipe(
v.string(),
v.isoDate(() => message("to")),
),
}),
v.forward(
v.partialCheck(
[["from"], ["to"]],
({ from, to }) => to >= from,
() => message("order"),
),
["to"],
),
),
{ abortPipeEarly: true },
);
export type InterestForm = v.InferOutput<ReturnType<typeof interestFormSchema>>;
|