UNPKG

node-warp

Version:

Web-agnostic Rapid Prototyping tools

28 lines (24 loc) 668 B
/** * Limits the number so it lies within a given range * @param {number} x * @param {number} [a = 0] * @param {number} [b = 1] * @return {number} */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function clamp(x) { var a = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; var b = arguments.length <= 2 || arguments[2] === undefined ? 1 : arguments[2]; if (a > b) { var _ref = [b, a]; a = _ref[0]; b = _ref[1]; } return ~ ~Math.max(a, Math.min(b, parseInt(x, 10))) | 0; } exports["default"] = { clamp: clamp }; module.exports = exports["default"]; //# sourceMappingURL=math.js.map