UNPKG

io-ts-types

Version:

A collection of codecs and combinators for use with io-ts

19 lines (18 loc) 610 B
/** * @since 0.4.5 */ import * as t from 'io-ts'; /** * A codec that succeeds if a string is not empty * * @example * import { NonEmptyString } from 'io-ts-types/es6/NonEmptyString' * import { right } from 'fp-ts/es6/Either' * import { PathReporter } from 'io-ts/es6/PathReporter' * * assert.deepStrictEqual(NonEmptyString.decode('a'), right('a')) * assert.deepStrictEqual(PathReporter.report(NonEmptyString.decode('')), ['Invalid value "" supplied to : NonEmptyString']) * * @since 0.4.5 */ export var NonEmptyString = t.brand(t.string, function (s) { return s.length > 0; }, 'NonEmptyString');