A Boolean that is definitely a Boolean that (with options) can be undefined or a string

Example

const sb       = SafeBoolean.create(true, { name: 'MyBoolean' });
const stringSb = SafeBoolean.create('true');
const undefSb = SafeBoolean.create(undefined, { allowUndefinedAs: true });

// extract the Result:
if (sb.isSuccess()) {
console.log(sb.getValue()) // SafeBoolean { _value: true }
}

Fails

  • if undefined (and not allowed to)
  • if not a (parsable) boolean

Hierarchy

Accessors

Methods

  • compares 2 Lists of ValueObjects / values on equality

    Returns

    true if the lists are equal

    Type Parameters

    • ValueType

    Parameters

    • a: ValueObject<ValueType>[]

      the list of ValueObjects to compare with

    • b: ValueObject<ValueType>[] | ValueType[]

      a list of ValueObjects / values for comparison

    Returns boolean

  • Returns

    the value if the validation was successful

    Fails

    if undefined (and not allowed to)

    Fails

    if not a (parsable) boolean

    Parameters

    • value: undefined | string | boolean

      to be validated as a valid boolean / string representation of a boolean

    • Optional options: SafeBooleanOptions

      constraints the value has to fulfill

    Returns Result<boolean>

Generated using TypeDoc