UNPKG

simple-jsrange

Version:

Simple range function for JavaScript

49 lines (34 loc) 1.64 kB
"use strict"; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var newRangeError = function newRangeError() { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var start = args[0], end = args[1], options = args[2]; var step = options.step, inc = options.inc; return new RangeError("Invalid args for range(" + start + "," + end + ") with options:{step: " + step + ", inc: " + inc + "}"); }; var throwInvalidRange = function throwInvalidRange() { throw newRangeError.apply(undefined, arguments); }; var checkValue = function checkValue(value) { var isNumber = typeof value === "number"; var isValidString = typeof value === "string" && value !== " " && value.length === 1; return isNumber || isValidString; }; var checkAllValues = function checkAllValues(start, end, options) { if (!checkValue(start) || !checkValue(end)) return true; if ((typeof start === "undefined" ? "undefined" : _typeof(start)) !== (typeof end === "undefined" ? "undefined" : _typeof(end))) return true; if (!Number.isInteger(options.step)) return true; if (options.step === 0) return true; if (options.step < 0) return true; return false; }; module.exports = { throwInvalidRange: throwInvalidRange, checkValue: checkValue, checkAllValues: checkAllValues };