★ Constructor
Creates the `Range` instance with a range of the given required `min`, `max` and optional current `value`, `step`
Range()
Range()
Creates the Range
instance with a range of the given required min
, max
and optional current value
, step
.
constructor(min: Min, max: Max, value?: number, step: Step = 1 as Step) {
this.#maximum = new Maximum(max);
this.#minimum = new Minimum(min);
this.#step = step;
// Sets the range value between the given `min` and `max`.
this.value = value;
// Define the `min` and `max` property.
Object.defineProperties(this, {
min: {
value: min,
enumerable: true,
writable: false,
},
max: {
value: max,
enumerable: true,
writable: false,
},
});
}
Parameters
The minimum range of generic type variable Min
to set with a new Range
instance.
The maximum range of generic type variable Max
to set with a new Range
instance.
The optional value of the number
type between the given min
and max
specifies the default value of a new Range
instance.
Optional step of generic type variable Step
to set with a new Range
instance, by default 1
.
Example usage
// Example usage.
import { Range } from '@angular-package/range';
// Returns Range {min: 4, max: 27} of Range<4, 27, 1>
new Range(4, 27);
// Returns Range {min: 4, max: 27, value: 27} of Range<4, 27, 1>
new Range(4, 27, 27);
// Returns Range {min: 4, max: 27, value: 5} of Range<4, 27, 1.5>
new Range(4, 27, 5, 1.5);
Last updated