UNPKG

@typescript-package/range

Version:

A lightweight TypeScript library for managing various types of ranges.

897 lines (887 loc) 40.4 kB
/** * The `Greater` primitive wrapper `object` represents the primitive value of the `number` type greater than the given. */ class Greater extends Number { /** * The `get` accessor, with the help of `toStringTag`, changes the default tag to `'Greater'` for an instance of `Greater`. It can be read * by the `typeOf()` function of `@angular-package/type`. * @returns The return value is the word 'Greater` of a `string`. */ get [Symbol.toStringTag]() { return 'Greater'; } //#region static public methods. /** * Creates the `Greater` instance with the given primitive `value`. * @param value The value of generic type variable `Value` to set with a newly created instance. * @returns The return value is the `Greater` instance with the primitive value of the given `value`. */ static create(value) { return new this(value); } /** * Checks whether the given `value` is the `Greater` instance of any or given primitive value. * @param value The value of any type to test against the `Greater` instance. * @param greaterValue An optional value of generic type variable `Value` to check whether it's the primitive value of the given `value`. * @returns The return value is a `boolean` indicating whether the given `value` is the `Greater` instance of any or given primitive * value. */ static isGreater(value, greaterValue) { return (typeof value === 'object' && value instanceof this && (typeof greaterValue === 'number' ? value.valueOf() === greaterValue : true)); } //#endregion static public methods. //#region constructor. /** * Creates the `Greater` instance with the given primitive `value`. * @param value The value of generic type variable `Value` to set with a new instance. */ constructor(value) { super(value); } //#endregion constructor. //#region instance public methods. /** * Checks whether the primitive value of a specified `object` is greater than the given `value`. * @param value The value of `number` type to test. * @returns The return value is a `boolean` indicating whether the primitive value is greater than the given value. */ than(value) { return typeof value === 'number' ? this.valueOf() > value : false; } /** * Checks whether the primitive value of a specified `object` is greater than every value of the given `values`. * @param values A rest parameter of the numbers to test. * @returns The return value is a `boolean` indicating whether the primitive value is greater than every value of the given `values`. */ thanEvery(...values) { return Array.isArray(values) ? values.every((value) => this.valueOf() > value) : false; } /** * Checks whether the primitive value of a specified `object` is greater than some given `values`. * @param values A rest parameter of the numbers to test. * @returns The return value is a `boolean` indicating whether the primitive value is greater than some given `values`. */ thanSome(...values) { return Array.isArray(values) ? values.some((value) => this.valueOf() > value) : false; } /** * Returns the primitive value of a specified `object`. * @returns The return value is the primitive value of generic type variable `Value`. */ valueOf() { return super.valueOf(); } } /** * The `Less` primitive wrapper `object` represents the primitive value of `number` type less than the given. */ class Less extends Number { //#region instance public accessors. /** * The `get` accessor, with the help of `toStringTag`, changes the default tag to `Less` for an instance of `Less`. It can be read * by the `typeOf()` function of `@angular-package/type`. * @returns The return value is the word 'Less` of a `string`. */ get [Symbol.toStringTag]() { return 'Less'; } //#endregion instance public accessors. //#region public static methods. /** * Creates the `Less` instance with the given primitive `value`. * @param value The value of generic type variable `Value` to set with a newly created instance. * @returns The return value is the `Less` instance with the primitive value of the given `value`. */ static create(value) { return new this(value); } /** * Checks whether the given `value` is the `Less` instance of any or given primitive value. * @param value The value of any type to test against the `Less` instance. * @param lessValue An optional value of generic type variable `Value` to check whether it's the primitive value of the given `value`. * @returns The return value is a `boolean` indicating whether the given `value` is the `Less` instance of any or given primitive * value. */ static isLess(value, lessValue) { return (typeof value === 'object' && value instanceof this && (typeof lessValue === 'number' ? value.valueOf() === lessValue : true)); } //#endregion public static methods. //#region constructor. /** * Creates the `Less` instance with the given `value`. * @param value The value of generic type variable `Value` to set with a new instance. */ constructor(value) { super(value); } //#endregion constructor. //#region instance public methods. /** * Checks whether the primitive value of a specified `object` is less than the given `value`. * @param value The value of number type to test. * @returns The return value is a `boolean` indicating whether the primitive value is less than the given value. */ than(value) { return typeof value === 'number' ? this.valueOf() < value : false; } /** * Checks whether the primitive value of a specified `object` is less than every given value. * @param values A rest parameter of the numbers to test. * @returns The return value is a `boolean` indicating whether the primitive value is less than every value of the given `values`. */ thanEvery(...values) { return Array.isArray(values) ? values.every((value) => this.valueOf() < value) : false; } /** * Checks whether the primitive value of a specified `object` is less than some given `values`. * @param values A rest parameter of the numbers to test. * @returns The return value is a `boolean` indicating whether the primitive value is less than some given `values`. */ thanSome(...values) { return Array.isArray(values) ? values.some((value) => this.valueOf() < value) : false; } /** * Returns the primitive value of a specified `object`. * @returns The return value is the primitive value of generic type variable `Value`. */ valueOf() { return super.valueOf(); } } // Class. /** * The `Inequality` abstract primitive wrapper `object` represents the primitive value greater or less than the given. */ class Inequality extends Number { //#region instance public accessors. /** * The `get` accessor obtains from the private `#greater` property an instance of the `Greater` with a primitive value from a given * `value` of the `Inequality` constructor. * @returns The return value is the `Greater` instance with a primitive value from the given `value` of the `Inequality` constructor. */ get greater() { return this.#greater; } /** * The `get` accessor obtains from the private `#less` property an instance of the `Less` with a primitive value from a given `value` of * the `Inequality` constructor. * @returns The return value is the `Less` instance with a primitive value from the given `value` of the `Inequality` constructor. */ get less() { return this.#less; } //#endregion instance public accessors. //#region instance private properties. /** * Private property of the `Greater` primitive wrapper `object` indicates the value of the `number` type greater than the given. */ #greater; /** * Private property of the `Less` primitive wrapper `object` indicates the value of `number` type less than the given. */ #less; //#endregion instance private properties. //#region constructor. /** * Creates a child class instance with the given primitive `value`. * @param value The value of the generic type variable `Value` is the primitive value of a new child class instance. */ constructor(value) { super(value); this.#greater = new Greater(value); this.#less = new Less(value); } //#endregion constructor. //#region instance public methods. /** * The `isBetween()` method checks whether the primitive value is between the range of a specified object. * @param min The minimum range of number type to test. * @param max The maximum range of number type to test. * @returns The return value is a `boolean` type indicating whether the primitive value is between the range of a specified object. */ isBetween(min, max) { return min < max ? (this.greaterThan(min) && this.lessThan(max)) || min === this.valueOf() || max === this.valueOf() : false; } /** * Checks whether the primitive value is between every range of the given `ranges`. * @param ranges A rest parameter of `array` type ranges to test. * @returns The return value is a `boolean` type indicating whether the primitive value is between every range of the * given `ranges`. */ isBetweenEvery(...ranges) { return ranges.every((range) => this.isBetween(range[0], range[1])); } /** * Checks whether the primitive value is between some given `ranges`. * @param ranges A rest parameter of `array` type ranges to test. * @returns The return value is a `boolean` type indicating whether the primitive value is between some given `ranges`. */ isBetweenSome(...ranges) { return ranges.some((range) => this.isBetween(range[0], range[1])); } /** * Checks whether the primitive value of a child class instance is greater than the given `value`. * @param value The value of `number` type to test. * @returns The return value is a `boolean` indicating whether the primitive value of a child class instance is greater than the given * `value`. */ greaterThan(value) { return this.#greater.than(value); } /** * Checks whether the primitive value of a child class instance is greater than every value of the given `values`. * @param values A rest parameter of the numbers to test. * @returns The return value is a `boolean` indicating whether the primitive value of a child class instance is greater than every value * of the given `values`. */ greaterThanEvery(...values) { return this.#greater.thanEvery(...values); } /** * Checks whether the primitive value of a child class instance is greater than some given `values`. * @param values A rest parameter of the numbers to test. * @returns The return value is a `boolean` indicating whether the primitive value of a child class instance is greater than some given * `values`. */ greaterThanSome(...values) { return this.#greater.thanSome(...values); } /** * Checks whether the primitive value of a child class instance is less than the given `value`. * @param value The value of `number` type to test. * @returns The return value is a `boolean` indicating whether the primitive value of a child class instance is **less** than the given * `value`. */ lessThan(value) { return this.#less.than(value); } /** * Checks whether the primitive value of a child class instance is less than every given value. * @param values A rest parameter of the numbers to test. * @returns The return value is a `boolean` indicating whether the primitive value of a child class instance is less than every value of * the given `values`. */ lessThanEvery(...values) { return this.#less.thanEvery(...values); } /** * Checks whether the primitive value of a child class instance is less than some given `values`. * @param values A rest parameter of the numbers to test. * @returns The return value is a `boolean` indicating whether the primitive value of a child class instance is less than some given * `values`. */ lessThanSome(...values) { return this.#less.thanSome(...values); } } // Class. /** * The `Maximum` primitive wrapper object extended by the `Inequality` abstract primitive wrapper `object` represents the maximum number * greater or less than the given. */ class Maximum extends Inequality { //#region instance public properties. /** * The `get` accessor, with the help of `toStringTag`, changes the default tag to `'Maximum'` for an instance of `Maximum`. It can be read * by the `typeOf()` function of `@angular-package/type`. */ get [Symbol.toStringTag]() { return 'Maximum'; } //#endregion instance public properties. //#region static public methods. /** * Creates the `Maximum` instance with the given primitive `value`. * @param value The maximum number of generic type variable `Value` to set with a new instance. * @returns The return value is the `Maximum` instance of the given primitive `value`. */ static create(value) { return new this(value); } /** * Checks whether the value of any type is the `Maximum` instance of any or the given primitive value. * @param value The value of any type to test against the `Maximum` instance. * @param max Optional maximum of the generic type variable `Value` to check if it's the primitive value of the given `value`. * @returns The return value is a `boolean` indicating whether the provided value is an instance of `Maximum`. */ static isMaximum(value, max) { return (typeof value === 'object' && value instanceof this && (typeof max === 'number' ? value.valueOf() === max : true)); } //#endregion static methods. //#region constructor. /** * Creates the `Maximum` instance of the given primitive `value`. * @param value The value of the generic type variable `Value` is the primitive value of the new instance. */ constructor(value) { super(value); } //#endregion constructor. //#region instance public methods. /** * The `valueOf()` method returns the primitive value of the generic type variable `Value` of the specified `Maximum` object. * @returns The return value is the primitive value of the generic type variable `Value`. */ valueOf() { return super.valueOf(); } } // Class. /** * The `Minimum` primitive wrapper object extended by the `Inequality` abstract primitive wrapper `object` represents the minimum number * greater or less than the given. */ class Minimum extends Inequality { //#region instance public properties. /** * The property, with the help of `toStringTag`, changes the default tag to `'Minimum'` for an instance of `Minimum`. It can be read by * the `typeOf()` function of `@angular-package/type`. */ get [Symbol.toStringTag]() { return 'Minimum'; } //#endregion instance public properties. //#region static public methods. /** * The static `create()` method creates the `Minimum` instance with the given primitive `value`. * @param value The minimum number of generic type variable `Value` to set with a new instance. * @returns The return value is the `Minimum` instance with the primitive value of the given `value`. */ static create(value) { return new this(value); } /** * The static `isMinimum()` method checks the provided `value` of any type whether is an instance of `Minimum` of any or the given `min`. * @param value The value of any type to test against the `Minimum` instance. * @param max Optional minimum of the generic type variable `Value` to check if it's the primitive value of the given `value`. * @returns The return value is a `boolean` indicating whether the provided `value` is an instance of `Minimum` of any or the given `min`. */ static isMinimum(value, min) { return (typeof value === 'object' && value instanceof this && (typeof min === 'number' ? value.valueOf() : true)); } //#endregion static public methods. //#region constructor. /** * Creates the `Minimum` instance of the given primitive `value`. * @param value The value of the generic type variable `Value` is the primitive value of the new instance. */ constructor(value) { super(value); } //#endregion constructor. //#region instance public methods. /** * The `valueOf()` method returns the primitive value of generic type variable `Value` of the specified `Minimum` object. * @returns The return value is the primitive value of generic type variable `Value`. */ valueOf() { return super.valueOf(); } } // Class. /** * The `Number` primitive wrapper object extended by the `Inequality` abstract primitive wrapper `object` represents the number greater or * less than the given. */ let Number$1 = class Number extends Inequality { //#region static public methods. /** * Creates the `Number` instance with the given primitive `value`. * @param value The number of generic type variable `Value` to set with a new instance. * @returns The return value is the `Number` instance of the given primitive `value`. */ static create(value) { return new this(value); } /** * Checks whether the value of any type is the `Number` instance of any or the given primitive value. * @param value The value of any type to test against the `Number` instance. * @param numberValue Optional number of the generic type variable `Value` to check if it's the primitive value of the given `value`. * @returns The return value is a `boolean` indicating whether the provided value is an instance of `Number` of any or the given * `numberValue`. */ static isNumber(value, numberValue) { return (typeof value === 'object' && value instanceof this && (typeof numberValue === 'number' ? value.valueOf() === numberValue : true)); } //#endregion static methods. //#region constructor. /** * Creates the `Number` instance of the given primitive `value`. * @param value The value of the generic type variable `Value` is the primitive value of the new instance. */ constructor(value) { super(value); } //#endregion constructor. //#region instance public methods. /** * The `valueOf()` method returns the primitive value of the generic type variable `Value` of the specified `Number` object. * @returns The return value is the primitive value of the generic type variable `Value`. */ valueOf() { return super.valueOf(); } }; // Class. /** * The `Range` object represents a range between a minimum and maximum. */ class Range { //#region instance accessors. /** * The `get` accessor obtains the range of an `Array` of the minimum to the maximum with the step of a specified `Range` object. * @returns The return value is the range from minimum to the maximum of a read-only `Array` of number. */ get range() { return this.getRange(); } /** * The `get` accessor obtains the step of a specified `Range` object. It's used to return the entire range, get the step of the range * value, and change the range value. * @returns The return value is the step of generic type variable `Step`. */ get step() { return this.#step; } /** * The `get` accessor retrieves the number of steps of the specified `Range` object. * @returns The return value is the number of steps of the `number` type. */ get steps() { return this.getRange().length; } /** * The `get` accessor retrieves the `#value` property that indicates the range current value of the `number` type of a specified `Range` * object. It can be set by the `setValue()` method. * @returns The return value is the range current value of `number` type if set, otherwise `undefined`. */ get value() { return this.#value; } /** * The `set` accessor sets the range current value of the `number` type between the minimum and maximum of a specified `Range` * object. * @returns The return value is the range current value of `number` type if set, otherwise `undefined`. */ set value(value) { typeof value === 'number' ? this.has(value) && (this.#value = value) : undefined; } /** * The property, with the help of `toStringTag`, changes the default tag to `'Range'` for an instance of `Range`. It can be read by the * `typeOf()` function of `@angular-package/type`. * @returnsThe return value is the word 'Range` of a `string`. */ get [Symbol.toStringTag]() { return 'Range'; } //#endregion instance accessors. //#region instance properties. //#region public instance properties. /** * The `max` read-only property is the maximum range of generic type variable `Max` of a specified `Range` object. */ max; /** * The `min` read-only property is the minimum range of generic type variable `Min` of a specified `Range` object. */ min; //#endregion public instance properties. //#region private instance properties. /** * Private property of the `Maximum` primitive wrapper `object` with a primitive value from a given `max` of the `Range` constructor * indicates the maximum range. */ #maximum; /** * Private property of the `Minimum` primitive wrapper `object` with a primitive value from a given `min` of the `Range` constructor * indicates the minimum range. */ #minimum; /** * The private property of the generic type variable `Step` indicates the range step. It's used to return the entire range, get the * step of the range value, and change the range value. */ #step; /** * The private property of the `number` type indicates the range value. It can be set by the `setValue()` method and setter `value`. */ #value; //#endregion private instance properties. //#endregion instance properties. //#region static public methods. /** * The static `create()` method returns a new instance of `Range` with a range of the given required `min`, `max` and optional current * `value`, `step`. * @param min The **minimum** range of generic type variable `Min` to set with a new `Range` instance. * @param max The **maximum** range of generic type variable `Max` to set with a new `Range` instance. * @param value The optional value of the `number` type between the given `min` and `max` specifies the default value of a new `Range` * instance. * @param step Optional step of generic type variable `Step` to set with a new `Range` instance, by default `1`. * @returns The return value is the `Range` instance with a range of the given required `min`, `max` and optional current `value`, `step`. */ static create(min, max, value, step) { return new this(min, max, value, step); } /** * Creates the `Range` instance from the given random numbers and the step. * @param numbers An `Array` of numbers to find a range and create a new instance. * @param step Optional step of generic type variable `Step` to set with a new `Range` instance, by default `1`. * @returns The return value is the `Range` instance created from the given required random numbers and the optional step. */ static createFrom(numbers, step = 1) { return Range.create(Math.min.apply(0, numbers), Math.max.apply(0, numbers), step); } /** * The static `createMaximum()` method returns the `Maximum` instance of the given maximum `value`. * @param value The maximum range of a generic type variable `Value` to set with a new instance of `Maximum`. * @returns The return value is the `Maximum` instance with the primitive value from the given `value`. */ static createMaximum(value) { return Maximum.create(value); } /** * The static `createMinimum()` method returns the `Minimum` instance of the given minimum `value`. * @param value The minimum range of a generic type variable `Value` to set with a new instance of `Minimum`. * @returns The return value is the `Minimum` instance with the primitive value from the given `value`. */ static createMinimum(value) { return Minimum.create(value); } /** * The static `isRange()` method checks whether the `value` is an instance of `Range` of any or the given minimum, maximum, and step. * @param value The value of any type to test against the `Range` instance. * @param min The optional minimum range of generic type variable `Min` to check whether it's equal to a minimum of the given `value`. * @param max The optional maximum range of generic type variable `Max` to check whether it's equal to a maximum of the given `value`. * @param step Optional step of generic type variable `Step` to check whether it's equal to the step of the given `value`. * @returns The return value is a boolean indicating whether the provided `value` is an instance of `Range` of any or the given minimum, * maximum range and step. */ static isRange(value, min, max, step) { return typeof value === 'object' && value instanceof this ? (typeof min === 'number' ? value.min === min : true) && (typeof max === 'number' ? value.max === max : true) && (typeof step === 'number' ? value.step === step : true) : false; } //#endregion static public methods. //#region constructor. /** * Creates the `Range` instance with a range of the given required `min`, `max` and optional current `value`, `step`. * @param min The minimum range of generic type variable `Min` to set with a new `Range` instance. * @param max The maximum range of generic type variable `Max` to set with a new `Range` instance. * @param value The optional value of the `number` type between the given `min` and `max` specifies the default value of a new `Range` * instance. * @param step 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. * @returns The return value is a new instance of `Range` of the given minimum and maximum. */ constructor(min, max, value, step = 1) { 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, }, }); } //#endregion constructor. //#region instance public methods. /** * The `forEachStep()` method performs the specified action for each step in the maximum range of an `Array`. * @param forEachStep A `function` that accepts up to three arguments. It's called one time for each step in the range. * @returns The return value is the `Range` instance. */ forEachStep(forEachStep) { this.range.forEach(forEachStep); return this; } /** * The `getCurrentRange()` method returns a range of numbers from minimum to the current value by the step of a specified `Range` object. * @returns The return value is a range of numbers of a read-only `Array` from minimum to the current value, if the current value is set, * otherwise `undefined`. */ getCurrentRange() { return typeof this.value === 'number' ? this.getRange(this.value) : undefined; } /** * The `getCurrentStep()` method returns the step of the range value. * @returns The return value is the step of `number` type, if range value is set, otherwise `undefined`. */ getCurrentStep() { return typeof this.value === 'number' ? Math.floor(this.value / this.#step) : undefined; } /** * @deprecated * The `getMax()` method gets the maximum range of a specified `Range` object. * @returns The return value is the maximum range of a generic type variable `Max`. */ getMax() { return this.#maximum.valueOf(); } /** * @deprecated * The `getMin()` method gets the minimum range of a specified `Range` object. * @returns The return value is the minimum range of a generic type variable `Min`. */ getMin() { return this.#minimum.valueOf(); } /** * The `getRange ()` method returns a range of numbers by the specified step from minimum to the given `value` of the specified` Range` * object. * @param value Optional maximum range value of `number` type of returned `array` by default it's the maximum range. * @returns The return value is a range of numbers of a read-only `Array` from minimum to the given `value`. */ getRange(value = this.max) { const range = []; let current = this.min; while (current <= value) { current <= this.max && range.push(current), (current += this.#step); } return range; } /** * The `getRangeOfStep()` method returns a range of numbers by the specified step from the minimum to the given `step` of a specified * `Range` object. * @param step Step of `number` type is the maximum range of the returned `array`. The value must be less or equal to the number of range * steps. * @returns The return value is a range of numbers of a read-only `Array` from minimum to step of the given `step` if the given `step` * is within a range, otherwise an empty `Array`. */ getRangeOfStep(step) { const range = []; if (step > 0 && step <= this.steps) { for (let value = 0; value < step; value++) { range.push(this.min + value * this.#step); } } return range; } /** * The `getValueOfStep()` method returns the range value of the given `step`. If the given `step` is not within range returns `undefined`. * @param step Step parameter of `number` type to retrieve the range value. * @returns The return value is the range value of the given `step` within a range otherwise `undefined`. */ getValueOfStep(step) { return step > 0 && step <= this.steps ? this.range[step - 1] : undefined; } /** * The `has()` method checks whether the value is in the range of a specified `Range` object. * @param value The value of `number` type to test. * @returns The return value is a `boolean` indicating whether the given `value` is in the range of a specified `Range` object. */ has(value) { return ((this.minLessThan(value) && this.maxGreaterThan(value)) || value === this.min || value === this.max); } /** * The `hasEvery()` method checks whether every value of the given `values` is in the range of a specified `Range` object. * @param value A rest parameter of numbers to test. * @returns The return value is a `boolean` indicating whether every value of the given `values` is in the range of a specified `Range` * object. */ hasEvery(...values) { return values.every((value) => this.has(value)); } /** * Checks whether some `values` are in the range of a specified `Range` object. * @param value A rest parameter of numbers to test. * @returns The return value is a `boolean` indicating whether some `values` are in the range of a specified `Range` object. */ hasSome(...values) { return values.some((value) => this.has(value)); } /** * The `isBetween()` method checks whether range of the given `min` and `max` is between the range of a specified `Range` object. * @param min The **minimum** range of `number` type to test. * @param max The **maximum** range of `number` type to test. * @returns The return value is a `boolean` type indicating whether the range of a specified `Range` object is between a range of the * given `min` and `max`. */ isBetween(min, max) { return min <= max ? this.hasEvery(min, max) : false; } /** * Checks whether the range of a specified `Range` object is between every range of the given `ranges`. * @param ranges A rest parameter of ranges of an `array` type to test. * @returns The return value is a `boolean` type indicating whether the range of a specified `Range` object is between every range of the * given `ranges`. */ isBetweenEvery(...ranges) { return ranges.every((range) => range[0] <= range[1] ? this.hasEvery(...range) : false); } /** * Checks whether the range of a specified `Range` object is between some given `ranges`. * @param ranges A rest parameter of an `array` type ranges to test. * @returns The return value is a `boolean` type indicating whether the range of a specified `Range` object is between some given * `ranges`. */ isBetweenSome(...ranges) { return ranges.some((range) => range[0] <= range[1] ? this.hasEvery(...range) : false); } /** * The `maxGreaterThan()` method checks whether the value is less than the maximum range of a specified `Range` object. * @param value The value of `number` type to test. * @returns The return value is a `boolean` type indicating whether the given `value` is less than maximum range of a specified `Range` * object. */ maxGreaterThan(value) { return this.#maximum.greaterThan(value); } /** * The `maxLessThan()` method checks whether the value is greater than the maximum range of a specified `Range` object. * @param value The value of `number` type to test. * @returns The return value is a `boolean` type indicating whether the given `value` is greater than maximum range of a specified `Range` * object. */ maxLessThan(value) { return this.#maximum.lessThan(value); } /** * The `minGreaterThan()` method checks whether the value is less than a minimum range of a specified `Range` object. * @param value The value of `number` type to test. * @returns The return value is a `boolean` type indicating whether the given `value` is less than minimum range of a specified `Range` * object. */ minGreaterThan(value) { return this.#minimum.greaterThan(value); } /** * The method `minLessThan()` checks whether the value is greater than the minimum range of a specified `Range` object. * @param value The value of `number` type to test. * @returns The return value is a `boolean` type indicating whether the given `value` is greater than minimum range of a specified `Range` * object. */ minLessThan(value) { return this.#minimum.lessThan(value); } /** * The method `setValue()` sets the range value between the minimum and maximum of a specified `Range` object. If the given `value` is not * within range, it's not set. * @param value The value of `number` type to set. * @returns The return value is the `Range` instance. */ setValue(value) { this.value = value; return this; } /** * The method `setValueToStep()` sets the value of the specified `Range` object to the value of the given `step`. If the given `step` is * not within range the value is not changed. * @param step Step of `number` type to retrieve the value from the range and set it as the range current `value`. * @returns The return value is the `Range` instance. */ setValueToStep(step) { step > 0 && (this.value = this.getValueOfStep(step)); return this; } /** * The `stepByStep()` method performs a callback function with the ability to decide when to move to the next step of the range. * @param callbackFn A function that accepts up to three arguments. The `value` is a function generator that allows deciding when to move * to the next step, `step` is the step, and `max` is the maximum of a specified `Range` object. * @returns The return value is the `Range` instance. */ stepByStep(callbackFn) { const t = this; callbackFn((function* stepByStep(current = t.min - t.step) { while (current < t.max) { yield (current += t.step); } })(), t.step, t.max); return this; } /** * @deprecated * The `toArray()` method returns a read-only array of the range in order minimum and maximum. * @returns The return value is a read-only array of the range in order minimum and maximum. */ toArray() { return [this.#minimum.valueOf(), this.#maximum.valueOf()]; } /** * The `valueDown()` method decrements the range value of a specified `Range` object by the range step or given `stepDecrement`. * @param stepIncrement The optional `stepDecrement` parameter of the `number` type decrements the range value. If no parameter is passed, * `stepDecrement` defaults to `1`. * @returns The return value is the `Range` instance. */ valueDown(stepDecrement = 1) { typeof this.value === 'number' && stepDecrement > 0 && this.setValue(this.value - stepDecrement * this.#step); return this; } /** * @deprecated * The `valueOf()` method returns a read-only object consisting of the primitive values of `Minimum` and `Maximum` instances. * @returns The return value is a frozen `object` consisting of the primitive values of `Minimum` and `Maximum` instances. */ valueOf() { return Object.freeze({ min: this.#minimum.valueOf(), max: this.#maximum.valueOf(), }); } /** * The `valueUp()` method increments the range value of a specified `Range` object by the range step or given `stepIncrement`. * @param stepIncrement The optional `stepIncrement` parameter of the `number` type increments the range value. If no parameter is passed, * `stepIncrement` defaults to `1`. * @returns The return value is the `Range` instance. */ valueUp(stepIncrement = 1) { typeof this.value === 'number' && stepIncrement > 0 && this.setValue(this.value + stepIncrement * this.#step); return this; } } /* * Public API Surface of range */ /** * Generated bundle index. Do not edit. */ export { Greater, Inequality, Less, Maximum, Minimum, Number$1 as Number, Range }; //# sourceMappingURL=typescript-package-range.mjs.map