A floating point number that can also be created from a string representation of a floating point number

Example

const floatString1      = FloatString.create(42.69, { name: 'MyFloat' });
const intFloatString1 = FloatString.create(42);
const rangeFloatString1 = FloatString.create(21.4, { min: 12.1, max: 41.9 });
const floatString2 = FloatString.create('42.69');
const intFloatString2 = FloatString.create('42');
const rangeFloatString2 = FloatString.create('21.4', { min: 12.1, max: 41.9 });

// extract the Result:
if (floatString2.isSuccess()) {
console.log(floatString2.getValue()) // FloatString { _value: 42.69 }
}

Fails

  • if the value is not a parsable number
  • if the value is not inside the interval

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 the value is not a parsable number

    Fails

    if the value is not inside the interval

    Parameters

    • value: string | number

      to be validated as a float with the corresponding constraints (options)

    • Optional options: FloatStringOptions

      constraints the value has to fulfill

    Returns Result<number>

Generated using TypeDoc