@daiso-tech/core
Version:
The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.
22 lines • 608 B
JavaScript
/**
* @module Utilities
*/
export class ValidationError extends Error {
constructor(issues) {
const jsonMessage = JSON.stringify(issues, null, 2);
super(`A validation error occured with the following issues:\n${jsonMessage}`);
this.name = ValidationError.name;
}
}
/**
* @internal
*
* @throws {ValidationError} {@link ValidationError}
*/
export async function validate(schema, value) {
const result = await schema?.["~standard"].validate(value);
if (result?.issues) {
throw new ValidationError(result.issues);
}
}
//# sourceMappingURL=validate.js.map