★ Constructor

Creates the `Range` instance with a range of the given required `min`, `max` and optional current `value`, `step`

Range()

Creates the Range instance with a range of the given required min, max and optional current value, step.

range.class.ts
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

min:Min

The minimum range of generic type variable Min to set with a new Range instance.

max:Max

The maximum range of generic type variable Max to set with a new Range instance.

value?:number

The optional value of the number type between the given min and max specifies the default value of a new Range instance.

step:Step=1 asStep

Optional step of generic type variable Step to set with a new Range instance, by default 1.

The step is used by the range accessor, getRange() , getRangeOfStep() and stepByStep() methods to return the entire range and also by the valueDown(), valueUp() methods to respectively decrement, increment range value.

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