is-integer-in-range
Version:
Tests if a value is an integer in a specified range
29 lines • 1.01 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.isIntegerInRangeFn = void 0;
const isInteger = require("is-integer");
/**
* Tests if the specified value is an integer in the specified range.
*
* The range is inclusive of the start and end values.
*/
function isIntegerInRange(value, start, end) {
if (typeof start !== "number" || typeof end !== "number") {
throw new TypeError("Expected start and end to be numbers");
}
return isInteger(value) && value >= start && value <= end;
}
exports.default = isIntegerInRange;
/**
* Curried variant of isIntegerInRange.
*
* Takes a range specified as a start and end value, and returns a function
* that tests if a specified value is an integer within the range.
*
* The range is inclusive of the start and end values.
*/
function isIntegerInRangeFn(start, end) {
return value => isIntegerInRange(value, start, end);
}
exports.isIntegerInRangeFn = isIntegerInRangeFn;
//# sourceMappingURL=index.js.map
;