1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 1x 1x 1x 1x 1x 16x 8x 8x 8x 1x | import { nonEmptyArray } from 'fp-ts/lib/NonEmptyArray'; import * as ValidationFn from 'fp-ts/lib/Validation'; import Decoder, { Decoded } from './Decoder'; export default class StringD extends Decoder<string> { public run(value: unknown): Decoded<string> { if (typeof value === 'string') { return ValidationFn.success(value); } const message = `Value must be a string, found "${typeof value}" instead`; return ValidationFn.failure(nonEmptyArray.of(message)); } } |