UNPKG

@respeecher/respeecher-js

Version:

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Frespeecher%2Frespeecher-js) [![npm shield](

44 lines (43 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.set = set; const Schema_js_1 = require("../../Schema.js"); const getErrorMessageForIncorrectType_js_1 = require("../../utils/getErrorMessageForIncorrectType.js"); const maybeSkipValidation_js_1 = require("../../utils/maybeSkipValidation.js"); const index_js_1 = require("../list/index.js"); const index_js_2 = require("../schema-utils/index.js"); function set(schema) { const listSchema = (0, index_js_1.list)(schema); const baseSchema = { parse: (raw, opts) => { const parsedList = listSchema.parse(raw, opts); if (parsedList.ok) { return { ok: true, value: new Set(parsedList.value), }; } else { return parsedList; } }, json: (parsed, opts) => { var _a; if (!(parsed instanceof Set)) { return { ok: false, errors: [ { path: (_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : [], message: (0, getErrorMessageForIncorrectType_js_1.getErrorMessageForIncorrectType)(parsed, "Set"), }, ], }; } const jsonList = listSchema.json([...parsed], opts); return jsonList; }, getType: () => Schema_js_1.SchemaType.SET, }; return Object.assign(Object.assign({}, (0, maybeSkipValidation_js_1.maybeSkipValidation)(baseSchema)), (0, index_js_2.getSchemaUtils)(baseSchema)); }