UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

23 lines (22 loc) • 936 B
//#region src/base-ui/FormKit/schema.ts const isStandardSchema = (value) => typeof value === "object" && value !== null && "~standard" in value; const issuePath = (issue) => (issue.path ?? []).map((segment) => String(typeof segment === "object" ? segment.key : segment)).join("."); const schemaToFormValidator = (schema) => async (values) => { const result = await schema["~standard"].validate(values); if (!result.issues) return void 0; const errors = {}; for (const issue of result.issues) { const path = issuePath(issue); if (errors[path] === void 0) errors[path] = issue.message; } return errors; }; const toFieldValidator = (validate) => { if (!isStandardSchema(validate)) return validate; return async (value) => { return (await validate["~standard"].validate(value)).issues?.[0]?.message; }; }; //#endregion export { isStandardSchema, schemaToFormValidator, toFieldValidator }; //# sourceMappingURL=schema.mjs.map