All files Null.ts

100% Statements 13/13
100% Branches 4/4
100% Functions 3/3
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 231x 1x   1x   1x       3x 3x     1x 4x 2x     2x 2x   1x  
import { nonEmptyArray } from 'fp-ts/lib/NonEmptyArray';
import * as ValidationFn from 'fp-ts/lib/Validation';
 
import Decoder, { Decoded } from './Decoder';
 
export default class NullD<a> extends Decoder<a> {
  private value: a;
 
  constructor(value: a) {
    super();
    this.value = value;
  }
 
  public run(value: unknown): Decoded<a> {
    if (value === null) {
      return ValidationFn.success(this.value);
    }
 
    const message = `Value must be a null, found "${typeof value}" instead`;
    return ValidationFn.failure(nonEmptyArray.of(message));
  }
}