UNPKG

@prismicio/types-internal

Version:
15 lines (14 loc) 592 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const Either_1 = require("fp-ts/Either"); const function_1 = require("fp-ts/function"); const t = (0, tslib_1.__importStar)(require("io-ts")); /** A codec that succeeds if a number can be parsed to an integer */ exports.default = new t.Type("IntFromNumber", t.Int.is, (u, c) => (0, function_1.pipe)(t.number.validate(u, c), (0, Either_1.chain)((n) => { if (t.Int.is(n)) return t.success(n); else { return t.success(Math.round(n)); } })), t.Int.encode);