-
Couldn't load subscription status.
- Fork 0
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!"-
↳
Integer↳↳
NumericId
- equals
- toJSON
- create
- fromList
- listEquals
- prefix
- toList
- validate
- validateInteger
- validateInterval
- validateList
- validateNumber
• Protected new Integer(value)
| Name | Type |
|---|---|
value |
number |
valueObjects/numeric/Integer.ts:22
• Protected Readonly _value: number
the actual value of the ValueObject
• get value(): T
the actual value of this ValueObject
T
Float.value
valueObjects/ValueObject.ts:13
▸ equals(obj): boolean
compares if the given value is either an equal ValueObject, or an equal value which would create an equal ValueObject
| Name | Type | Description |
|---|---|---|
obj |
number | Integer
|
to compare of equality |
boolean
valueObjects/numeric/Integer.ts:26
▸ toJSON(): number
this function is invoked by JSON.stringify() and converts the inner "_propertyKey" to "propertyKey"
number
the value
valueObjects/ValueObject.ts:61
▸ Static create(value, options?): Integer
| Name | Type | Description |
|---|---|---|
value |
number |
to create the ValueObject of |
options? |
IntegerOptions |
constraints the value has to fulfill |
the created ValueObject
valueObjects/numeric/Integer.ts:95
▸ Static fromList(values, options?): Integer[]
| 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 |
Integer[]
the array of ValueObjects
valueObjects/numeric/Integer.ts:104
▸ Static listEquals<ValueType>(a, b): boolean
compares 2 Lists of ValueObjects / values on equality
| Name |
|---|
ValueType |
| Name | Type | Description |
|---|---|---|
a |
ValueObject<ValueType>[] |
the list of ValueObjects to compare with |
b |
ValueObject<ValueType>[] | ValueType[] |
a list of ValueObjects / values for comparison |
boolean
true if the lists are equal
valueObjects/ValueObject.ts:29
▸ 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';| 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"
|
string
the name of the ValueObject
valueObjects/ValueObject.ts:77
▸ Static toList(values): number[]
| Name | Type | Description |
|---|---|---|
values |
Integer[] |
an array of ValueObjects to map to an array of their values |
number[]
the array of values
valueObjects/numeric/Integer.ts:115
▸ 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
| Name | Type | Description |
|---|---|---|
value |
number |
to be validated as an integer with the corresponding constraints (options) |
options? |
IntegerOptions |
constraints the value has to fulfill |
number
the value if the validation was successful
valueObjects/numeric/Integer.ts:40
▸ Static Protected validateInteger(value, options?): number
If defined in the options the number will possibly be rounded.
| Name | Type | Description |
|---|---|---|
value |
number |
to be validated as a valid integer |
options? |
IntegerOptions |
constraints the value has to fulfill |
number
the (possibly rounded) integer
valueObjects/numeric/Integer.ts:55
▸ Static Protected validateInterval(value, options): void
| Name | Type |
|---|---|
value |
string | number
|
options |
IntervalCreationOptions |
void
valueObjects/ValueObject.ts:86
▸ Static Protected validateList<Primitive>(list, options?): list is Primitive[]
| Name |
|---|
Primitive |
| Name | Type |
|---|---|
list |
undefined | Primitive[] |
options? |
CreationOptions & ListCreationOptions
|
list is Primitive[]
valueObjects/ValueObject.ts:101
▸ Static Protected validateNumber(value, options?): void
| Name | Type | Description |
|---|---|---|
value |
number |
to be validated as a valid number (not NaN) |
options? |
IntervalCreationOptions |
constraints the value has to fulfill |
void