Skip to content

NonEmptyString

Christian Prinz edited this page Oct 17, 2022 · 1 revision

Class: NonEmptyString

A String that is definitely a String that is not empty

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

Protected new NonEmptyString(value)

Parameters

Name Type
value string

Overrides

OptionalString.constructor

Defined in

valueObjects/string/NonEmptyString.ts:6

Properties

_value

Protected Readonly _value: string

the actual value of the ValueObject

Inherited from

OptionalString._value

Defined in

valueObjects/ValueObject.ts:4

Accessors

value

get value(): T

the actual value of this ValueObject

Returns

T

Inherited from

OptionalString.value

Defined in

valueObjects/ValueObject.ts:13

Methods

equals

equals(obj): boolean

compares if the given value is either an equal ValueObject, or an equal value which would create an equal ValueObject

Parameters

Name Type Description
obj string | NonEmptyString to compare of equality

Returns

boolean

Overrides

OptionalString.equals

Defined in

valueObjects/string/NonEmptyString.ts:10


toJSON

toJSON(): string

this function is invoked by JSON.stringify() and converts the inner "_propertyKey" to "propertyKey"

Returns

string

the value

Inherited from

OptionalString.toJSON

Defined in

valueObjects/ValueObject.ts:61


create

Static create(value, options?): NonEmptyString

Parameters

Name Type Description
value string to create the ValueObject of
options? NonEmptyStringOptions constraints the value has to fulfill

Returns

NonEmptyString

the created ValueObject

Overrides

OptionalString.create

Defined in

valueObjects/string/NonEmptyString.ts:89


format

Static Protected format(value, options?): string

Throws

Error if the formatting failed

Parameters

Name Type Description
value string to be formatted with the given formatting options
options? OptionalStringOptions constraints the value has to fulfill

Returns

string

the formatted string

Inherited from

OptionalString.format

Defined in

valueObjects/string/OptionalString.ts:70


fromList

Static fromList(values, options?): NonEmptyString[]

Parameters

Name Type Description
values undefined | string[] an array of primitives to map to an array of ValueObjects
options? NonEmptyStringOptions & ListCreationOptions constraints the values / list has to fulfill

Returns

NonEmptyString[]

the array of ValueObjects

Overrides

OptionalString.fromList

Defined in

valueObjects/string/NonEmptyString.ts:98


listEquals

Static listEquals<ValueType>(a, b): boolean

compares 2 Lists of ValueObjects / values on equality

Type parameters

Name
ValueType

Parameters

Name Type Description
a ValueObject<ValueType>[] the list of ValueObjects to compare with
b ValueObject<ValueType>[] | ValueType[] a list of ValueObjects / values for comparison

Returns

boolean

true if the lists are equal

Inherited from

OptionalString.listEquals

Defined in

valueObjects/ValueObject.ts:29


prefix

Static Protected prefix(options, addition?): string

constructs a prefix for possible error messages based on the ValueObjects name and an additional string:

  • example for NonEmptyString with name='Person':
"Person > NonEmptyString"

Parameters

Name Type Default value Description
options undefined | CreationOptions undefined the CreationOptions where the optional name: string is taken from
addition string '' An additional name which will be added as "name.addition"

Returns

string

the name of the ValueObject

Inherited from

OptionalString.prefix

Defined in

valueObjects/ValueObject.ts:77


toList

Static toList(values): string[]

Parameters

Name Type Description
values NonEmptyString[] an array of ValueObjects to map to an array of their values

Returns

string[]

the array of values

Overrides

OptionalString.toList

Defined in

valueObjects/string/NonEmptyString.ts:109


validate

Static validate(value, options?): string

Throws

TypeError if not a string or empty

Throws

TypeError if the value doesn't fit the given enum

Throws

RangeError if the value is not matching the regex

Throws

RangeError if the value's length is not inside the interval

Parameters

Name Type Description
value string to be validated as a not empty string with the corresponding constraints (options)
options? NonEmptyStringOptions constraints the value has to fulfill

Returns

string

the value if the validation was successful

Overrides

OptionalString.validate

Defined in

valueObjects/string/NonEmptyString.ts:25


validateInterval

Static Protected validateInterval(value, options): void

Parameters

Name Type
value string | number
options IntervalCreationOptions

Returns

void

Inherited from

OptionalString.validateInterval

Defined in

valueObjects/ValueObject.ts:86


validateList

Static Protected validateList<Primitive>(list, options?): list is Primitive[]

Type parameters

Name
Primitive

Parameters

Name Type
list undefined | Primitive[]
options? CreationOptions & ListCreationOptions

Returns

list is Primitive[]

Inherited from

OptionalString.validateList

Defined in

valueObjects/ValueObject.ts:101


validateNonEmptyString

Static Private validateNonEmptyString(value, options): void

Parameters

Name Type Description
value string to be validated as a valid string that is not the empty string ("")
options undefined | NonEmptyStringOptions constraints the value has to fulfill

Returns

void

Defined in

valueObjects/string/NonEmptyString.ts:43


validateRange

Static Private validateRange(value, options): void

Parameters

Name Type Description
value string to be validated to match a given range (enum / string[])
options NonEmptyStringOptions constraints the value has to fulfill

Returns

void

Defined in

valueObjects/string/NonEmptyString.ts:61


validateRegex

Static Protected validateRegex(value, options): void

Parameters

Name Type Description
value string to be validated to match the given regular expression
options OptionalStringOptions constraints the value has to fulfill

Returns

void

Inherited from

OptionalString.validateRegex

Defined in

valueObjects/string/OptionalString.ts:39


validateString

Static Protected validateString(value, options?): void

Parameters

Name Type Description
value string to be validated as a valid string
options? OptionalStringOptions constraints the value has to fulfill

Returns

void

Inherited from

OptionalString.validateString

Defined in

valueObjects/string/OptionalString.ts:55

DDD basics - v0.0.1

Clone this wiki locally