A String that is definitely a String that is not empty

Example

const nes      = NonEmptyString.create('foo', { name: 'MyNES' });
const rangeNes = NonEmptyString.create('bar', { range: ['foo', 'bar', 'baz'] });
enum myEnum {
'foo',
'bar',
'baz',
}
const enumNes = NonEmptyString.create('baz', { range: myEnum });
const enumNes2 = NonEmptyString.create(myEnum.baz, { range: myEnum });
const sizeNes = NonEmptyString.create('long_enough', { min: 3, max: 69 });
const regexNes = NonEmptyString.create('foo', { regex: /oo/ });

// extract the Result:
if (nes.isSuccess()) {
console.log(nes.getValue()) // NonEmptyString { _value: 'foo' }
}

Fails

  • if not a string or empty
  • if the value doesn't fit the given enum / range
  • if the value is not matching the regex
  • if the value's length is not inside the interval

Hierarchy

Accessors

Methods

  • Returns

    the value if the validation was successful

    Fails

    if not a string or empty

    Fails

    if the value doesn't fit the given enum / range

    Fails

    if the value is not matching the regex

    Fails

    if the value's length is not inside the interval

    Parameters

    • value: string

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

    • Optional options: NonEmptyStringOptions

      constraints the value has to fulfill

    Returns Result<string>

Generated using TypeDoc