Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/local/share/.cache/yarn/v6/npm-pesa-1.1.12-integrity/node_modules/pesa/dist/ drwxr-xr-x | |
| Viewing file: Select action/file-type: var __defProp = Object.defineProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __accessCheck = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateGet = (obj, member, getter) => {
__accessCheck(obj, member, "read from private field");
return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd = (obj, member, value) => {
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateSet = (obj, member, value, setter) => {
__accessCheck(obj, member, "write to private field");
setter ? setter.call(obj, value) : member.set(obj, value);
return value;
};
var __privateMethod = (obj, member, method) => {
__accessCheck(obj, member, "access private method");
return method;
};
// index.ts
__export(exports, {
Money: () => Money,
PreciseNumber: () => PreciseNumber,
getMoneyMaker: () => getMoneyMaker,
getPreciseNumberMaker: () => getPreciseNumberMaker,
p: () => p,
pesa: () => pesa
});
// src/consts.ts
var MIN_PREC = 0;
var MAX_PREC = 36;
var DEF_PREC = 6;
var DEF_DISP = 3;
var USE_BNKR = true;
// src/utils.ts
function replaceDelimiters(value) {
if (typeof value === "string") {
return value.replace(/[_,]/g, "");
}
return value;
}
function scaler(value, precision) {
var _a;
value = replaceDelimiters(value);
throwIfNotValid(value);
value = stripZeros(value);
const fractionalLength = getFractionalLength(value);
const stringRep = typeof value === "number" ? value.toString() : value;
const floatRep = typeof value === "string" ? parseFloat(value) : value;
const parts = stringRep.split(".");
const whole = parts[0];
const fractional = (_a = parts[1]) != null ? _a : "";
let stringBigRep = whole + fractional;
stringBigRep = stringBigRep === "-0" ? "0" : stringBigRep;
let bigRep = BigInt(stringBigRep);
if (precision > fractionalLength) {
bigRep *= 10n ** BigInt(precision - fractionalLength);
} else {
bigRep /= 10n ** BigInt(fractionalLength - precision);
if (parseInt(fractional[precision]) > 4) {
bigRep += floatRep >= 0 ? 1n : -1n;
}
}
return bigRep;
}
function getFractionalLength(value) {
const string = value.toString();
const whereIsTheDot = string.indexOf(".") + 1;
if (whereIsTheDot === 0) {
return 0;
}
return string.substring(whereIsTheDot).length;
}
function throwIfNotValid(value) {
const type = typeof value;
if (type === "string" && !getIsInputValid(value)) {
throw Error(`invalid input '${value}' of type '${type}'`);
}
}
function getIsInputValid(value) {
const hasMatch = value.match(/^-?\d*(?:(?:\.?\d)|(?:\d\.?))\d*$/);
return Boolean(hasMatch);
}
function toDecimalString(value, precision) {
const isNegative = value < 0;
let stringRep = value.toString();
stringRep = isNegative ? stringRep.slice(1) : stringRep;
const d = stringRep.length - precision;
const sign = isNegative ? "-" : "";
if (d < 0) {
return sign + stripZeros("0." + "0".repeat(Math.abs(d)) + stringRep);
} else if (d === 0) {
return sign + stripZeros("0." + stringRep);
}
const whole = stringRep.slice(0, d) || "0";
const fractional = stringRep.slice(d);
if (fractional.length) {
return sign + stripZeros(`${whole}.${fractional}`);
}
return sign + whole;
}
function stripZeros(value) {
if (typeof value === "string" && value.includes(".") && value.endsWith("0")) {
let [fractional, whole] = value.split(".");
whole = whole.replace(/0*$/, "");
whole = whole.length > 0 ? `.${whole}` : whole;
return fractional + whole;
}
return value;
}
function getIsCurrencyCode(code) {
return !!code.match(/^[A-Z]{3}$/);
}
function throwIfInvalidCurrencyCode(code) {
if (!getIsCurrencyCode(code)) {
throw Error(`invalid currency code '${code}'`);
}
}
function getConversionRateKey(from, to) {
const keys = [from, to];
keys.forEach(throwIfInvalidCurrencyCode);
return keys.join("-");
}
function matchPrecision(value, from, to) {
if (from > to) {
return value / 10n ** BigInt(from - to);
} else if (from < to) {
return value * 10n ** BigInt(to - from);
}
return value;
}
function throwRateNotProvided(from, to) {
throw Error(`rate not provided for conversion from ${from} to ${to}`);
}
// src/preciseNumber.ts
var Operator;
(function(Operator2) {
Operator2["Add"] = "+";
Operator2["Sub"] = "-";
Operator2["Mul"] = "*";
Operator2["Div"] = "/";
})(Operator || (Operator = {}));
var Comparator;
(function(Comparator2) {
Comparator2["Eq"] = "===";
Comparator2["Gt"] = ">";
Comparator2["Lt"] = "<";
Comparator2["Gte"] = ">=";
Comparator2["Lte"] = "<=";
})(Comparator || (Comparator = {}));
var _precision, _value, _bankersRounding, _throwIfInvalidInput, throwIfInvalidInput_fn, _scaleAndConvert, scaleAndConvert_fn, _neutralizedMul, neutralizedMul_fn, _executeOperation, executeOperation_fn, _executeComparison, executeComparison_fn, _validateAndGetPrecision, validateAndGetPrecision_fn, _splitInput, splitInput_fn;
var _PreciseNumber = class {
constructor(value = 0n, precision = DEF_PREC, bankersRounding = USE_BNKR) {
__privateAdd(this, _throwIfInvalidInput);
__privateAdd(this, _scaleAndConvert);
__privateAdd(this, _neutralizedMul);
__privateAdd(this, _executeOperation);
__privateAdd(this, _executeComparison);
__privateAdd(this, _validateAndGetPrecision);
__privateAdd(this, _precision, void 0);
__privateAdd(this, _value, void 0);
__privateAdd(this, _bankersRounding, void 0);
precision = __privateMethod(this, _validateAndGetPrecision, validateAndGetPrecision_fn).call(this, precision);
__privateSet(this, _value, 0n);
__privateSet(this, _precision, precision);
__privateSet(this, _bankersRounding, bankersRounding);
this.value = value;
}
_setInnerValue(value) {
__privateMethod(this, _throwIfInvalidInput, throwIfInvalidInput_fn).call(this, value);
__privateSet(this, _value, value);
}
round(to, bankersRounding) {
bankersRounding != null ? bankersRounding : bankersRounding = __privateGet(this, _bankersRounding);
__privateMethod(this, _throwIfInvalidInput, throwIfInvalidInput_fn).call(this, to);
to = to >= 0 ? to : 0;
const diff = to - __privateGet(this, _precision);
const isNeg = __privateGet(this, _value) < 0;
let stringRep = __privateGet(this, _value).toString().slice(isNeg ? 1 : 0);
if (stringRep.length < this.precision) {
stringRep = "0".repeat(this.precision - stringRep.length) + stringRep;
}
const dpoint = stringRep.length - this.precision;
const whole = stringRep.slice(0, dpoint) || "0";
const fraction = stringRep.slice(dpoint);
const trailingZeros = "0".repeat(Math.max(0, diff));
const ultimateDigit = parseInt(fraction[to]);
const isMid = ultimateDigit === 5 && [...fraction.slice(to + 1)].every((d) => d === "0");
let roundingDigit = (ultimateDigit || 0) <= 4 ? 0n : isNeg && isMid ? 0n : 1n;
if (bankersRounding && isMid && trailingZeros.length === 0) {
const penultimateDigit = parseInt(to - 1 >= 0 ? fraction[to - 1] : whole[dpoint - 1]) || 0;
roundingDigit = penultimateDigit % 2 === 0 ? 0n : 1n;
}
let lowPrescisionRep = (BigInt(whole + fraction.slice(0, to) + trailingZeros) + roundingDigit).toString();
if (lowPrescisionRep.length < to) {
lowPrescisionRep = "0".repeat(to - lowPrescisionRep.length) + lowPrescisionRep;
}
const newDpoint = lowPrescisionRep.length - to;
const newWhole = lowPrescisionRep.slice(0, newDpoint) || "0";
const newFractional = lowPrescisionRep.slice(newDpoint);
const tail = "." + newFractional + "0".repeat(to - newFractional.length);
const noSign = newWhole + (tail !== "." ? tail : "");
return (!isNeg || [...noSign].filter((d) => d !== ".").every((d) => d === "0") ? "" : "-") + noSign;
}
clip(to) {
__privateMethod(this, _throwIfInvalidInput, throwIfInvalidInput_fn).call(this, to);
return new _PreciseNumber(this.round(to), __privateGet(this, _precision));
}
copy() {
const pn = new _PreciseNumber(0n, __privateGet(this, _precision));
pn._setInnerValue(__privateGet(this, _value));
return pn;
}
get value() {
return Number(__privateGet(this, _value)) / Math.pow(10, __privateGet(this, _precision));
}
set value(value) {
__privateMethod(this, _throwIfInvalidInput, throwIfInvalidInput_fn).call(this, value);
__privateSet(this, _value, __privateMethod(this, _scaleAndConvert, scaleAndConvert_fn).call(this, value));
}
get float() {
return this.value;
}
get integer() {
return __privateGet(this, _value);
}
get precision() {
return __privateGet(this, _precision);
}
set precision(precision) {
precision = __privateMethod(this, _validateAndGetPrecision, validateAndGetPrecision_fn).call(this, precision);
__privateSet(this, _value, matchPrecision(__privateGet(this, _value), this.precision, __privateGet(this, _precision)));
__privateSet(this, _precision, __privateGet(this, _precision));
}
get v() {
return this.value;
}
set v(value) {
this.value = value;
}
get i() {
return this.integer;
}
add(...values) {
return __privateMethod(this, _executeOperation, executeOperation_fn).call(this, Operator.Add, ...[this, ...values]);
}
sub(...values) {
return __privateMethod(this, _executeOperation, executeOperation_fn).call(this, Operator.Sub, ...[this, ...values]);
}
mul(...values) {
return __privateMethod(this, _executeOperation, executeOperation_fn).call(this, Operator.Mul, ...[this, ...values]);
}
div(...values) {
return __privateMethod(this, _executeOperation, executeOperation_fn).call(this, Operator.Div, ...[this, ...values]);
}
static add(...values) {
const [first, remaining] = __privateMethod(this, _splitInput, splitInput_fn).call(this, values);
return new this(first).add(...remaining);
}
static sub(...values) {
const [first, remaining] = __privateMethod(this, _splitInput, splitInput_fn).call(this, values);
return new this(first).sub(...remaining);
}
static mul(...values) {
const [first, remaining] = __privateMethod(this, _splitInput, splitInput_fn).call(this, values);
return new this(first).mul(...remaining);
}
static div(...values) {
const [first, remaining] = __privateMethod(this, _splitInput, splitInput_fn).call(this, values);
return new this(first).div(...remaining);
}
eq(value) {
return __privateMethod(this, _executeComparison, executeComparison_fn).call(this, Comparator.Eq, this, value);
}
gt(value) {
return __privateMethod(this, _executeComparison, executeComparison_fn).call(this, Comparator.Gt, this, value);
}
lt(value) {
return __privateMethod(this, _executeComparison, executeComparison_fn).call(this, Comparator.Lt, this, value);
}
gte(value) {
return __privateMethod(this, _executeComparison, executeComparison_fn).call(this, Comparator.Gte, this, value);
}
lte(value) {
return __privateMethod(this, _executeComparison, executeComparison_fn).call(this, Comparator.Lte, this, value);
}
static eq(valueA, valueB) {
return new this(valueA).eq(valueB);
}
static gt(valueA, valueB) {
return new this(valueA).gt(valueB);
}
static lt(valueA, valueB) {
return new this(valueA).lt(valueB);
}
static gte(valueA, valueB) {
return new this(valueA).gte(valueB);
}
static lte(valueA, valueB) {
return new this(valueA).lte(valueB);
}
isPositive() {
return __privateGet(this, _value) > 0n;
}
isNegative() {
return __privateGet(this, _value) < 0n;
}
isZero() {
return __privateGet(this, _value) === 0n;
}
toString() {
return toDecimalString(__privateGet(this, _value), __privateGet(this, _precision));
}
toJSON() {
return toDecimalString(__privateGet(this, _value), __privateGet(this, _precision));
}
valueOf() {
return __privateGet(this, _value);
}
};
var PreciseNumber = _PreciseNumber;
_precision = new WeakMap();
_value = new WeakMap();
_bankersRounding = new WeakMap();
_throwIfInvalidInput = new WeakSet();
throwIfInvalidInput_fn = function(...values) {
values.forEach((value) => {
if (value === 0 || value === 0n) {
return;
}
if (Number.isNaN(value) || value === Infinity || value === -Infinity || !value) {
throw Error(`invalid value ${value} found`);
}
});
};
_scaleAndConvert = new WeakSet();
scaleAndConvert_fn = function(value) {
if (value instanceof _PreciseNumber) {
return matchPrecision(value.integer, value.precision, this.precision);
}
if (typeof value === "bigint") {
return value;
}
return scaler(value, __privateGet(this, _precision));
};
_neutralizedMul = new WeakSet();
neutralizedMul_fn = function(product, neutralizer) {
const final = product / neutralizer;
const temp = product.toString();
const roundingNum = parseInt(temp.charAt(temp.length - __privateGet(this, _precision)) || "0") > 4 ? 1n : 0n;
return final + roundingNum;
};
_executeOperation = new WeakSet();
executeOperation_fn = function(operator, ...values) {
__privateMethod(this, _throwIfInvalidInput, throwIfInvalidInput_fn).call(this, ...values);
const neutralizer = 10n ** BigInt(__privateGet(this, _precision));
const prAmounts = values.map(__privateMethod(this, _scaleAndConvert, scaleAndConvert_fn), this);
const finalAmount = prAmounts.reduce((a, b) => {
switch (operator) {
case Operator.Add:
return a + b;
case Operator.Sub:
return a - b;
case Operator.Div:
return a * neutralizer / b;
case Operator.Mul:
return __privateMethod(this, _neutralizedMul, neutralizedMul_fn).call(this, a * b, neutralizer);
default:
return 0n;
}
});
const result = new _PreciseNumber(0n, __privateGet(this, _precision));
result._setInnerValue(finalAmount);
return result;
};
_executeComparison = new WeakSet();
executeComparison_fn = function(comparator, valueA, valueB) {
__privateMethod(this, _throwIfInvalidInput, throwIfInvalidInput_fn).call(this, valueA, valueB);
const prAmountA = __privateMethod(this, _scaleAndConvert, scaleAndConvert_fn).call(this, valueA);
const prAmountB = __privateMethod(this, _scaleAndConvert, scaleAndConvert_fn).call(this, valueB);
switch (comparator) {
case "===":
return prAmountA === prAmountB;
case ">":
return prAmountA > prAmountB;
case "<":
return prAmountA < prAmountB;
case ">=":
return prAmountA >= prAmountB;
case "<=":
return prAmountA <= prAmountB;
default:
return false;
}
};
_validateAndGetPrecision = new WeakSet();
validateAndGetPrecision_fn = function(precision) {
precision = Math.round(precision);
if (precision > MAX_PREC || precision < MIN_PREC) {
throw Error(`precision should be between ${MIN_PREC} and ${MAX_PREC}`);
}
return precision;
};
_splitInput = new WeakSet();
splitInput_fn = function(values) {
return [values[0], values.slice(1)];
};
__privateAdd(PreciseNumber, _splitInput);
// src/money.ts
var _currency, _wrapper, _preciseNumber, _conversionRates, _throwCurrencyNotSetIfNotSet, throwCurrencyNotSetIfNotSet_fn, _copySelf, copySelf_fn, _convertInput, convertInput_fn;
var _Money = class {
constructor(amount, options = {}) {
__privateAdd(this, _throwCurrencyNotSetIfNotSet);
__privateAdd(this, _copySelf);
__privateAdd(this, _convertInput);
__privateAdd(this, _currency, void 0);
__privateAdd(this, _wrapper, void 0);
__privateAdd(this, _preciseNumber, void 0);
__privateAdd(this, _conversionRates, void 0);
var _a, _b, _c, _d;
__privateSet(this, _preciseNumber, new PreciseNumber(amount, (_a = options.precision) != null ? _a : DEF_PREC, (_b = options.bankersRounding) != null ? _b : USE_BNKR));
__privateSet(this, _currency, "");
__privateSet(this, _conversionRates, new Map());
__privateSet(this, _wrapper, (_c = options.wrapper) != null ? _c : (m) => m);
this.display = (_d = options.display) != null ? _d : DEF_DISP;
const { currency, rates } = options;
if (currency) {
this.currency(currency);
}
if (rates) {
this.rate(rates);
}
return __privateGet(this, _wrapper).call(this, this);
}
get float() {
return __privateGet(this, _preciseNumber).value;
}
get options() {
const rates = Array.from(__privateGet(this, _conversionRates).keys()).map((k) => {
var _a;
const [from, to] = k.split("-");
const rate = (_a = __privateGet(this, _conversionRates).get(k)) != null ? _a : -1;
return { from, to, rate };
});
return {
currency: __privateGet(this, _currency),
precision: __privateGet(this, _preciseNumber).precision,
display: this.display,
rates
};
}
get preciseNumber() {
return __privateGet(this, _preciseNumber);
}
get internal() {
const bigint = __privateGet(this, _preciseNumber).integer;
const precision = __privateGet(this, _preciseNumber).precision;
return { bigint, precision };
}
get conversionRates() {
return new Map(__privateGet(this, _conversionRates));
}
get store() {
const { precision } = __privateGet(this, _preciseNumber);
return __privateGet(this, _preciseNumber).round(precision);
}
_setConversionRates(rates) {
if (__privateGet(this, _conversionRates).size === 0) {
__privateSet(this, _conversionRates, new Map(rates));
}
}
currency(value) {
if (!__privateGet(this, _currency)) {
throwIfInvalidCurrencyCode(value);
__privateSet(this, _currency, value);
}
return this;
}
rate(input, rate) {
if (typeof input === "string") {
__privateMethod(this, _throwCurrencyNotSetIfNotSet, throwCurrencyNotSetIfNotSet_fn).call(this);
}
if (typeof input === "string" && typeof rate === "undefined") {
throwRateNotProvided(__privateGet(this, _currency), input);
}
let settings;
if (input instanceof Array) {
settings = input;
} else if (typeof input === "string") {
settings = [
{
from: __privateGet(this, _currency),
to: input,
rate: rate != null ? rate : 1
}
];
} else if (input instanceof Object) {
settings = [input];
} else {
throw Error(`invalid input to rate: ${input}`);
}
for (let setting of settings) {
const { from, to, rate: rate2 } = setting;
const key = getConversionRateKey(from, to);
__privateGet(this, _conversionRates).set(key, rate2);
}
return this;
}
to(to, rate) {
__privateMethod(this, _throwCurrencyNotSetIfNotSet, throwCurrencyNotSetIfNotSet_fn).call(this);
if (typeof rate === "number" || typeof rate === "string" && !this.hasConversionRate(to)) {
this.rate(to, rate);
} else {
rate = this.getConversionRate(__privateGet(this, _currency), to);
}
const preciseNumber = __privateGet(this, _preciseNumber).mul(rate);
return __privateMethod(this, _copySelf, copySelf_fn).call(this, preciseNumber, to);
}
add(value, currency, rate) {
const { lhs, rhs } = __privateMethod(this, _convertInput, convertInput_fn).call(this, value, currency, rate);
const outPreciseNumber = lhs.add(rhs);
return __privateMethod(this, _copySelf, copySelf_fn).call(this, outPreciseNumber);
}
sub(value, currency, rate) {
const { lhs, rhs } = __privateMethod(this, _convertInput, convertInput_fn).call(this, value, currency, rate);
const outPreciseNumber = lhs.sub(rhs);
return __privateMethod(this, _copySelf, copySelf_fn).call(this, outPreciseNumber);
}
mul(value, currency, rate) {
const { lhs, rhs } = __privateMethod(this, _convertInput, convertInput_fn).call(this, value, currency, rate);
const outPreciseNumber = lhs.mul(rhs);
return __privateMethod(this, _copySelf, copySelf_fn).call(this, outPreciseNumber);
}
div(value, currency, rate) {
const { lhs, rhs } = __privateMethod(this, _convertInput, convertInput_fn).call(this, value, currency, rate);
const outPreciseNumber = lhs.div(rhs);
return __privateMethod(this, _copySelf, copySelf_fn).call(this, outPreciseNumber);
}
percent(value) {
return __privateMethod(this, _copySelf, copySelf_fn).call(this, __privateGet(this, _preciseNumber).mul(value / 100));
}
split(values, round) {
round != null ? round : round = this.display;
let percents = [];
if (typeof values === "number") {
const n = values;
percents = Array(n - 1).fill(100 / n).map((v) => new PreciseNumber(v, __privateGet(this, _preciseNumber).precision).clip(round != null ? round : DEF_DISP).float);
percents.push(100 - percents.reduce((a, b) => a + b));
} else if (values instanceof Array) {
percents = values;
}
const isFull = percents.map((v) => new PreciseNumber(v)).reduce((a, b) => a.add(b)).float === 100;
const final = isFull ? percents.length - 1 : percents.length;
const splits = percents.slice(0, final).map((v) => {
const rounded = __privateGet(this, _preciseNumber).mul(v / 100).round(round != null ? round : DEF_DISP);
return __privateMethod(this, _copySelf, copySelf_fn).call(this, rounded);
});
if (isFull) {
const sum = splits.reduce((a, b) => a.add(b)).round(round);
const finalMoney = __privateMethod(this, _copySelf, copySelf_fn).call(this, this.round(round)).sub(sum);
splits.push(finalMoney);
}
return splits;
}
abs() {
if (this.lt(0)) {
return this.mul(-1);
}
return this.copy();
}
neg() {
return this.mul(-1);
}
clip(to) {
to != null ? to : to = this.display;
return __privateMethod(this, _copySelf, copySelf_fn).call(this, __privateGet(this, _preciseNumber).clip(to), __privateGet(this, _currency));
}
copy() {
return __privateMethod(this, _copySelf, copySelf_fn).call(this, __privateGet(this, _preciseNumber).copy(), __privateGet(this, _currency));
}
eq(value, currency, rate) {
const { lhs, rhs } = __privateMethod(this, _convertInput, convertInput_fn).call(this, value, currency, rate);
return lhs.eq(rhs);
}
neq(value, currency, rate) {
const { lhs, rhs } = __privateMethod(this, _convertInput, convertInput_fn).call(this, value, currency, rate);
return !lhs.eq(rhs);
}
gt(value, currency, rate) {
const { lhs, rhs } = __privateMethod(this, _convertInput, convertInput_fn).call(this, value, currency, rate);
return lhs.gt(rhs);
}
lt(value, currency, rate) {
const { lhs, rhs } = __privateMethod(this, _convertInput, convertInput_fn).call(this, value, currency, rate);
return lhs.lt(rhs);
}
gte(value, currency, rate) {
const { lhs, rhs } = __privateMethod(this, _convertInput, convertInput_fn).call(this, value, currency, rate);
return lhs.gte(rhs);
}
lte(value, currency, rate) {
const { lhs, rhs } = __privateMethod(this, _convertInput, convertInput_fn).call(this, value, currency, rate);
return lhs.lte(rhs);
}
isPositive() {
return __privateGet(this, _preciseNumber).integer > 0n;
}
isNegative() {
return __privateGet(this, _preciseNumber).integer < 0n;
}
isZero() {
return __privateGet(this, _preciseNumber).integer === 0n;
}
getCurrency() {
return __privateGet(this, _currency);
}
getConversionRate(from, to) {
let key = getConversionRateKey(from, to);
let value = __privateGet(this, _conversionRates).get(key);
if (!value) {
key = getConversionRateKey(to, from);
value = __privateGet(this, _conversionRates).get(key);
if (value && typeof value === "string") {
value = 1 / parseFloat(value);
} else if (value && typeof value === "number") {
value = 1 / value;
}
}
if (!value) {
throw Error(`please set the conversion rate for ${from} to ${to}`);
}
return value;
}
hasConversionRate(to) {
let key = getConversionRateKey(this.getCurrency(), to);
let keyInverse = getConversionRateKey(to, this.getCurrency());
return __privateGet(this, _conversionRates).has(key) || __privateGet(this, _conversionRates).has(keyInverse);
}
round(to) {
to != null ? to : to = this.display;
return __privateGet(this, _preciseNumber).round(to);
}
toString() {
return __privateGet(this, _preciseNumber).toString();
}
toJSON() {
return __privateGet(this, _preciseNumber).toJSON();
}
valueOf() {
return __privateGet(this, _preciseNumber).valueOf();
}
};
var Money = _Money;
_currency = new WeakMap();
_wrapper = new WeakMap();
_preciseNumber = new WeakMap();
_conversionRates = new WeakMap();
_throwCurrencyNotSetIfNotSet = new WeakSet();
throwCurrencyNotSetIfNotSet_fn = function() {
if (!__privateGet(this, _currency)) {
throw Error("currency has not been set for conversion");
}
};
_copySelf = new WeakSet();
copySelf_fn = function(value, currency = "") {
const options = {
currency: currency || __privateGet(this, _currency),
precision: __privateGet(this, _preciseNumber).precision,
display: this.display,
wrapper: __privateGet(this, _wrapper)
};
const result = new _Money(value, options);
result._setConversionRates(__privateGet(this, _conversionRates));
return result;
};
_convertInput = new WeakSet();
convertInput_fn = function(value, currency, rate) {
let rhs;
const valueIsMoney = value instanceof _Money;
if (valueIsMoney) {
rhs = value.preciseNumber;
currency = value.getCurrency() || currency;
} else {
rhs = new PreciseNumber(value, __privateGet(this, _preciseNumber).precision);
}
if (currency && currency !== __privateGet(this, _currency)) {
let finalRate;
if (rate) {
finalRate = rate;
}
if (!finalRate && valueIsMoney) {
try {
finalRate = value.getConversionRate(currency, __privateGet(this, _currency));
} catch {
}
}
if (!finalRate) {
try {
finalRate = this.getConversionRate(currency, __privateGet(this, _currency));
} catch {
}
}
if (!finalRate) {
throwRateNotProvided(currency, __privateGet(this, _currency));
}
rhs = rhs.mul(finalRate != null ? finalRate : 1);
}
let lhs = __privateGet(this, _preciseNumber);
return { lhs, rhs };
};
// index.ts
function p(value = 0, precision = 6) {
return new PreciseNumber(value, precision);
}
function pesa(value = 0, options = {}) {
if (typeof options === "string") {
options = { currency: options };
}
return new Money(value, options);
}
function getPreciseNumberMaker(precision = DEF_PREC) {
return function(value, innerPrecision) {
return p(value, innerPrecision != null ? innerPrecision : precision);
};
}
function getMoneyMaker(options = {}) {
return function(value, innerOptions) {
return pesa(value, innerOptions != null ? innerOptions : options);
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Money,
PreciseNumber,
getMoneyMaker,
getPreciseNumberMaker,
p,
pesa
});
//# sourceMappingURL=pesa.js.map
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0062 ]-- |