UNPKG

@macalinao/zod-solana

Version:

Zod schemas for Solana types with @solana/kit integration

24 lines (23 loc) 916 B
import { U64_MAX } from "./constants.js"; import * as z from "zod"; //#region src/u64-string-schema.ts /** * A Zod schema for u64 values as strings. * Validates that a string represents a valid u64 value (0 to 2^64-1). * Returns the value as a string to preserve precision for large numbers. */ const u64StringSchema = z.string().refine((val) => { if (val === "") return false; if (val !== val.trim()) return false; if (val.startsWith("+") || val.startsWith("0x") || val.startsWith("0X") || val.startsWith("0b") || val.startsWith("0B") || val.startsWith("0o") || val.startsWith("0O")) return false; if (!/^\d+$/.test(val)) return false; try { const num = BigInt(val); return num >= 0n && num <= 18446744073709551615n; } catch { return false; } }, { message: `Value must be a valid u64 (0 to ${String(U64_MAX)})` }); //#endregion export { u64StringSchema }; //# sourceMappingURL=u64-string-schema.js.map