UNPKG

tshex-cli

Version:

Typescript Hexagonal Architecture CLI

88 lines (56 loc) 1.62 kB
// Libraries // Same Layer import ValueObject from './ValueObject.js'; import ValueError from '../errors/ValueError.js'; // Lower Layers // Types type T = boolean | null; // Constants /** * @description */ export default class NullableBooleanValueObject extends ValueObject { [property: string]: unknown; // public ATTRIBUTES public override readonly value: T; // protected ATTRIBUTES // private ATTRIBUTES // public static ATTRIBUTES // protected static ATTRIBUTES // private static ATTRIBUTES // Constructor, Getters, Setters protected constructor(value: T) { super(); this.value = value; } // public METHODS public override equals(other: NullableBooleanValueObject | null | undefined): boolean { if (other === null || other === undefined) { return false; } return this.value === other.value; } public isIndeterminate(): boolean { return this.value === null; } // protected METHODS // private METHODS // public static METHODS public static override isValid(value: unknown): boolean { return (value === null) || (value === true) || (value === false); } public static from(value: T): NullableBooleanValueObject { if (!this.isValid(value)) { throw new ValueError(value, this.name); } return new this(value); } // protected static METHODS // private static METHODS } //:: class