UNPKG

@dinero.js/calculator-number

Version:

Number calculator implementation for Dinero.js

182 lines (162 loc) 4.67 kB
/*! @dinero.js/calculator-number 2.0.0-alpha.1 | MIT License | © Sarah Dayan and contributors | https://dinero.js.com/calculator-number */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['@dinero.js/calculator-number'] = {})); }(this, (function (exports) { 'use strict'; /** * Returns the sum of two numbers. * * @param augend - The number to add to. * @param addend - The number to add. * * @returns The sum of the two numbers. */ var add = function add(augend, addend) { return augend + addend; }; /* eslint-disable functional/no-mixed-type */ var ComparisonOperator; (function (ComparisonOperator) { ComparisonOperator[ComparisonOperator["LT"] = -1] = "LT"; ComparisonOperator[ComparisonOperator["EQ"] = 0] = "EQ"; ComparisonOperator[ComparisonOperator["GT"] = 1] = "GT"; })(ComparisonOperator || (ComparisonOperator = {})); /** * Compare two numbers. * * @param a - The first number to compare. * @param b - The second number to compare. * * @returns Whether the two numbers are equal, or whether the first one is greater or less than the other. */ var compare = function compare(a, b) { if (a < b) { return ComparisonOperator.LT; } if (a > b) { return ComparisonOperator.GT; } return ComparisonOperator.EQ; }; /** * Returns an decremented number. * * @param value - The number to decrement. * * @returns The decremented number. */ var decrement = function decrement(value) { return value - 1; }; /** * Returns an incremented number. * * @param value - The number to increment. * * @returns The incremented number. */ var increment = function increment(value) { return value + 1; }; /** * Returns the quotient of two numbers with no fractional part. * * @param dividend - The number to divide. * @param divisor - The number to divide with. * * @returns The quotient of the two numbers. */ var integerDivide = function integerDivide(dividend, divisor) { return Math.trunc(dividend / divisor); }; /** * Returns the remainder of two numbers. * * @param dividend - The number to divide. * @param divisor - The number to divide with. * * @returns The remainder of the two numbers. */ var modulo = function modulo(dividend, divisor) { return dividend % divisor; }; /** * Returns the product of two numbers. * * @param multiplicand - The number to multiply. * @param multiplier - The number to multiply with. * * @returns The product of the two numbers. */ var multiply = function multiply(multiplicand, multiplier) { return multiplicand * multiplier; }; /** * Returns an number to the power of an exponent. * * @param base - The base number. * @param exponent - The exponent to raise the base to. * * @returns The base to the power of the exponent. */ var power = function power(base, exponent) { return Math.pow(base, exponent); }; /** * Returns the difference between two numbers. * * @param minuend - The number to subtract from. * @param subtrahend - The number to subtract. * * @returns The difference of the two numbers. */ var subtract = function subtract(minuend, subtrahend) { return minuend - subtrahend; }; /** * Transforms an value to a number. * * @param input - The value to transform. * * @returns The transformed value. */ var toNumber = function toNumber(input) { return input; }; /** * Return zero as a number. * * @returns Zero as a number. */ function zero() { return 0; } var calculator = { add: add, compare: compare, decrement: decrement, increment: increment, integerDivide: integerDivide, modulo: modulo, multiply: multiply, power: power, subtract: subtract, toNumber: toNumber, zero: zero }; exports.add = add; exports.calculator = calculator; exports.compare = compare; exports.decrement = decrement; exports.increment = increment; exports.integerDivide = integerDivide; exports.modulo = modulo; exports.multiply = multiply; exports.power = power; exports.subtract = subtract; exports.toNumber = toNumber; exports.zero = zero; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=index.development.js.map