UNPKG

dilswer

Version:

Blazingly fast data validation library with TypeScript integration.

50 lines (48 loc) 1.78 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/data-types/generate-standard-schema.ts var generate_standard_schema_exports = {}; __export(generate_standard_schema_exports, { getStandardSchemaProps: () => getStandardSchemaProps }); module.exports = __toCommonJS(generate_standard_schema_exports); var import_path = require("../validation-algorithms/path.cjs"); var import_validation_error = require("../validation-algorithms/validation-error/validation-error.cjs"); function getStandardSchemaProps(type) { var _a; const root = import_path.Path.init("$"); let validate = (_a = type["compiledValidatorRef"].fn) != null ? _a : (value) => { try { type["~validate"](root, value); return { value }; } catch (error) { if (import_validation_error.ValidationError.isValidationError(error)) { return { issues: [{ path: error.pathSegments, message: error.message }] }; } throw error; } }; return { version: 1, vendor: "Dilswer", validate }; }