UNPKG

sveltekit-superforms-5

Version:

<p align="center"> <img src="https://github.com/ciscoheat/sveltekit-superforms/raw/main/logo.svg" width="150px" align="center" alt="Superforms logo" /> <h1 align="center">Superforms 💥</h1> <p align="center">Making SvelteKit forms a pleasure to use!

42 lines (41 loc) • 1.28 kB
import { createAdapter, createJsonSchema } from './adapters.js'; import { memoize } from '../memoize.js'; async function modules() { const { type } = await import(/* webpackIgnore: true */ 'arktype'); return { type }; } const fetchModule = /* @__PURE__ */ memoize(modules); async function _validate(schema, data) { const { type } = await fetchModule(); const result = schema(data); if (!(result instanceof type.errors)) { return { data: result, success: true }; } const issues = []; for (const error of result) { issues.push({ message: error.problem, path: Array.from(error.path) }); } return { issues, success: false }; } function _arktype(schema, options) { return createAdapter({ superFormValidationLibrary: 'arktype', defaults: options.defaults, jsonSchema: createJsonSchema(options), validate: async (data) => _validate(schema, data) }); } function _arktypeClient(schema) { return { superFormValidationLibrary: 'arktype', validate: async (data) => _validate(schema, data) }; } export const arktype = /* @__PURE__ */ memoize(_arktype); export const arktypeClient = /* @__PURE__ */ memoize(_arktypeClient);