Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/bombshell-dev/configliere. A statically typed entry-point router for command-line applications
Something went wrong. Try again.
742 B · 28 lines
TypeScript
1234567891011121314151617181920212223242526272829import type { StandardSchemaV1 } from "@standard-schema/spec";import type { Source } from "./types.ts";
export function validate<T>( schema: StandardSchemaV1<T>, value: unknown,): StandardSchemaV1.Result<T> { let validation = schema["~standard"].validate(value); if (validation instanceof Promise) { throw new Error(`async validation is not supported`); } return validation;}
export class ValidationError extends Error { constructor(public sources: Source<unknown>[]) { super( sources.flatMap((source) => { if (source.issues) { return [source.issues.map((i) => i.message)]; } else { return []; } }).join("\n"), ); this.name = "ValidationError"; }}