UNPKG

@prismicio/types-internal

Version:
20 lines (17 loc) 443 B
import { chain } from "fp-ts/Either" import { pipe } from "fp-ts/function" import * as t from "io-ts" export type StringFromNumberC = t.Type<string, string, unknown> /** A codec that validates a number and convert it as a string */ export default new t.Type<string, string, unknown>( "StringFromInt", t.string.is, (u, c) => pipe( t.number.validate(u, c), chain((i) => { return t.success(i.toString()) }), ), (i) => i, )