UNPKG

basic-math-utils

Version:

Basic math utilities for doing some basic math operations

42 lines (33 loc) 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var RangeUtils = function () { function RangeUtils() { _classCallCheck(this, RangeUtils); } _createClass(RangeUtils, [{ key: "mapBetween", /** * Convert a value within a range to it's equivalent within another map range * * This function is usefull for example to convert a range like a ProgressBar range to it's equivalent in % * @param valueNow * @param valueMin * @param valueMax * @param rangeMin * @param rangeMax * @returns {number} */ value: function mapBetween(valueNow, valueMin, valueMax) { var rangeMin = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; var rangeMax = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 100; return (rangeMax - rangeMin) * (valueNow - valueMin) / (valueMax - valueMin) + rangeMin; // eslint-disable-line no-mixed-operators } }]); return RangeUtils; }(); exports.default = new RangeUtils(); module.exports = exports["default"];