UNPKG

react-application-core

Version:

A react-based application core for the business applications.

104 lines 3.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NumberUtils = void 0; var R = require("ramda"); var default_definition_interface_1 = require("../definition/default-definition.interface"); /** * @stable [01.09.2020] * @param num * @param precision */ var roundByPrecision = function (num, precision) { if (precision === void 0) { precision = default_definition_interface_1.DefaultEntities.CURRENCY_PRECISION_VALUE; } return R.isNil(num) ? num : Number(Math.round(Number(num + "e" + precision)) + "e-" + precision); }; /** * @stable [20.08.2020] * @param num * @param divider */ var roundDownByDivider = function (num, divider) { return Math.floor(num - num % divider); }; /** * @stable [24.07.2020] * @param num */ var invert = function (num) { return num === 0 ? num : num * -1; }; // To exclude the "-0" case /** * @stable [20.08.2020] * @param value * @param total */ var percent = function (value, total) { return total === 0 ? 0 : (value * 100) / total; }; /** * @stable [20.08.2020] * @param value * @param total */ var roundedPercent = function (value, total) { return Math.round(percent(value, total)); }; /** * @stable [20.08.2020] * @param value * @param total */ var proportion = function (value, total) { return (value * total) / 100; }; /** * @stable [20.08.2020] * @param divider * @param num */ var residueRoundDownByDivider = function (num, divider) { if (divider === void 0) { divider = default_definition_interface_1.DefaultEntities.UNIT_OF_CURRENCY; } return num - roundDownByDivider(num, divider); }; /** * @stable [20.08.2020] * @param value * @param total * @param offValue */ var roundedProportion = function (value, total, offValue) { if (offValue === void 0) { offValue = default_definition_interface_1.DefaultEntities.UNIT_OF_CURRENCY; } var result = proportion(value, total); return result + residueRoundDownByDivider(total - result, offValue); }; /** * @stable [20.08.2020] * @param value * @param total * @param offValue * @param precisionValue */ var roundedByPrecisionProportion = function (value, total, offValue, precisionValue) { if (offValue === void 0) { offValue = default_definition_interface_1.DefaultEntities.UNIT_OF_CURRENCY; } if (precisionValue === void 0) { precisionValue = default_definition_interface_1.DefaultEntities.CURRENCY_PRECISION_VALUE; } return roundByPrecision(roundedProportion(value, total, offValue), precisionValue); }; /** * @stable [17.08.2020] * @param value */ var isOddNumber = function (value) { return value % 2 !== 0; }; /** * @stable [29.06.2020] */ var NumberUtils = /** @class */ (function () { function NumberUtils() { } NumberUtils.invert = invert; NumberUtils.isOddNumber = isOddNumber; NumberUtils.percent = percent; NumberUtils.proportion = proportion; NumberUtils.residueRoundDownByDivider = residueRoundDownByDivider; NumberUtils.roundByPrecision = roundByPrecision; NumberUtils.roundDownByDivider = roundDownByDivider; NumberUtils.roundedByPrecisionProportion = roundedByPrecisionProportion; NumberUtils.roundedPercent = roundedPercent; NumberUtils.roundedProportion = roundedProportion; return NumberUtils; }()); exports.NumberUtils = NumberUtils; //# sourceMappingURL=number.js.map