UNPKG

pragmatic-fp-ts

Version:

Opinionated functional programming library with easy use in mind

18 lines (17 loc) 724 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const identity_1 = require("./identity"); const isString_1 = require("./isString"); const validate_1 = __importDefault(require("./validate")); const tryCatch_1 = require("./tryCatch"); const Decoder = (validate, parse = JSON.parse) => (x) => { const xx = (0, isString_1.isString)(x) ? (0, tryCatch_1.tryCatch)(parse, identity_1.identity, x) : x; return validate(xx); }; exports.default = { from: (name, validate, parse) => Decoder(validate_1.default.from(name, validate), parse), Decoder, };