A String that can be also created from either "" or undefined

  • undefined ends up being converted to ""

Example

const optStr      = OptionalString.create('not empty', {name: 'MyOptStr'});
const optStr2 = OptionalString.create(''); // a.value === ''
const optStr3 = OptionalString.create(undefined); // a.value === ''
const sizeOptStr = OptionalString.create('foo', {min: 3, max: 4});
const regexOptStr = OptionalString.create('foo', {regex: /fo/});

// extract the Result:
if (optStr3.isSuccess()) {
console.log(optStr3.getValue()) // OptionalString { _value: '' }
}

Fails

  • if not a string (when defined)
  • if the value is not matching the regex (when defined)
  • if the value is not inside the interval (when defined)

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 not a string (when defined)

    Fails

    if the value is not matching the regex (when defined)

    Fails

    if the value is not inside the interval (when defined)

    Parameters

    • value: string

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

    • Optional options: OptionalStringOptions

    Returns Result<string>

Generated using TypeDoc