Skip to content

Integer

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

Class: Integer

An Integer (number without decimal digits)

Example

// create a correct Integer
const mi = Integer.create(42, { name: 'MyInteger' }); // a.value === 42
const mi = Integer.create(42.3, { name: 'MyRounded', round: 'floor' }); // a.value === 42

const mi2 = Integer.create('aw', { name: 'MyInteger2' });
// throws "TypeError: MyInteger2 > Integer: the given value (aw: string) must be a number!"

const mi3 = Integer.create(42, { name: 'MyInteger3', min: 12, max: 41 });
// throws "RangeError: MyInteger3 > Integer: the given number (42) must be in the interval [12, 41]!"

const mi4 = Integer.create(6.9, { name: 'MyInteger4', round: 'deny' });
// throws "RangeError: MyInteger4 > Integer: the given value (6.9) must be an integer but has decimal places!"

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

Protected new Integer(value)

Parameters

Name Type
value number

Overrides

Float.constructor

Defined in

valueObjects/numeric/Integer.ts:22

Properties

_value

Protected Readonly _value: number

the actual value of the ValueObject

Inherited from

Float._value

Defined in

valueObjects/ValueObject.ts:4

Accessors

value

get value(): T

the actual value of this ValueObject

Returns

T

Inherited from

Float.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 number | Integer to compare of equality

Returns

boolean

Overrides

Float.equals

Defined in

valueObjects/numeric/Integer.ts:26


toJSON

toJSON(): number

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

Returns

number

the value

Inherited from

Float.toJSON

Defined in

valueObjects/ValueObject.ts:61


create

Static create(value, options?): Integer

Parameters

Name Type Description
value number to create the ValueObject of
options? IntegerOptions constraints the value has to fulfill

Returns

Integer

the created ValueObject

Overrides

Float.create

Defined in

valueObjects/numeric/Integer.ts:95


fromList

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

Parameters

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

Returns

Integer[]

the array of ValueObjects

Overrides

Float.fromList

Defined in

valueObjects/numeric/Integer.ts:104


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

Float.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

Float.prefix

Defined in

valueObjects/ValueObject.ts:77


toList

Static toList(values): number[]

Parameters

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

Returns

number[]

the array of values

Overrides

Float.toList

Defined in

valueObjects/numeric/Integer.ts:115


validate

Static validate(value, options?): number

Throws

TypeError if not a valid integer

Throws

RangeError if the value has not allowed decimal digits

Throws

RangeError if the value is not inside the interval

Parameters

Name Type Description
value number to be validated as an integer with the corresponding constraints (options)
options? IntegerOptions constraints the value has to fulfill

Returns

number

the value if the validation was successful

Overrides

Float.validate

Defined in

valueObjects/numeric/Integer.ts:40


validateInteger

Static Protected validateInteger(value, options?): number

If defined in the options the number will possibly be rounded.

Parameters

Name Type Description
value number to be validated as a valid integer
options? IntegerOptions constraints the value has to fulfill

Returns

number

the (possibly rounded) integer

Defined in

valueObjects/numeric/Integer.ts:55


validateInterval

Static Protected validateInterval(value, options): void

Parameters

Name Type
value string | number
options IntervalCreationOptions

Returns

void

Inherited from

Float.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

Float.validateList

Defined in

valueObjects/ValueObject.ts:101


validateNumber

Static Protected validateNumber(value, options?): void

Parameters

Name Type Description
value number to be validated as a valid number (not NaN)
options? IntervalCreationOptions constraints the value has to fulfill

Returns

void

Inherited from

Float.validateNumber

Defined in

valueObjects/numeric/Float.ts:35

DDD basics - v0.0.1

Clone this wiki locally