An Integer (number without decimal digits) that can also be created from a string representation of an integer

  • this is an extension of Integer, so you can also create from numbers

Example

const intString1      = IntegerString.create(42, { name: 'MyInteger' });
const roundIntString1 = IntegerString.create(42.6, { round: 'floor' });
const rangeIntString1 = IntegerString.create(42, { min: 12, max: 43 });
const intString2 = IntegerString.create('42', { name: 'MyInteger' });
const roundIntString2 = IntegerString.create('42.6', { round: 'floor' });
const rangeIntString2 = IntegerString.create('42', { min: 12, max: 43 });

// extract the Result:
if (intString2.isSuccess()) {
console.log(intString2.getValue()) // IntegerString { _value: 42 }
}

Fails

  • if not a parsable integer
  • if the value has not allowed decimal digits
  • 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

  • parses the given string to an integer (number).

    Returns

    the parsed number OR NaN if not parsable

    Parameters

    • value: string

      to parse (unchecked)

    Returns number

  • Returns

    the value if the validation was successful

    Fails

    if not a parsable integer

    Fails

    if the value has not allowed decimal digits

    Fails

    if the value is not inside the interval

    Parameters

    • value: string | number

      to be validated as an integer with the corresponding constraints (options)

    • Optional options: IntegerStringOptions

      constraints the value has to fulfill

    Returns Result<number>

Generated using TypeDoc