@lyxa.ai/types 1.0.305 → 1.0.306
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToSecondarySync = exports.roundCurrencySync = void 0;
|
|
4
|
+
const roundCurrencySync = (amount, roundingFactor) => {
|
|
5
|
+
if (amount == 0)
|
|
6
|
+
return 0;
|
|
7
|
+
const rounded = Math.ceil(amount / roundingFactor) * roundingFactor;
|
|
8
|
+
const decimals = (roundingFactor.toString().split('.')[1] || '').length;
|
|
9
|
+
return Number(rounded.toFixed(decimals));
|
|
10
|
+
};
|
|
11
|
+
exports.roundCurrencySync = roundCurrencySync;
|
|
12
|
+
const convertToSecondarySync = (price, exchangeRate, roundTo) => {
|
|
13
|
+
if (price == 0)
|
|
14
|
+
return 0;
|
|
15
|
+
if (price == null)
|
|
16
|
+
return null;
|
|
17
|
+
const amount = price * exchangeRate;
|
|
18
|
+
if (!roundTo)
|
|
19
|
+
return amount;
|
|
20
|
+
return (0, exports.roundCurrencySync)(amount, roundTo);
|
|
21
|
+
};
|
|
22
|
+
exports.convertToSecondarySync = convertToSecondarySync;
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utilities/currency/index.ts"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAE,cAAsB,EAAU,EAAE;IACnF,IAAI,MAAM,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,cAAc,CAAC,GAAG,cAAc,CAAC;IACpE,MAAM,QAAQ,GAAG,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IACxE,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC;AALW,QAAA,iBAAiB,qBAK5B;AAEK,MAAM,sBAAsB,GAAG,CAAC,KAAa,EAAE,YAAoB,EAAE,OAAe,EAAE,EAAE;IAC9F,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IACzB,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IAC/B,MAAM,MAAM,GAAG,KAAK,GAAG,YAAY,CAAC;IACpC,IAAI,CAAC,OAAO;QAAE,OAAO,MAAM,CAAC;IAC5B,OAAO,IAAA,yBAAiB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC,CAAC;AANW,QAAA,sBAAsB,0BAMjC","sourcesContent":["export const roundCurrencySync = (amount: number, roundingFactor: number): number => {\n\tif (amount == 0) return 0;\n\tconst rounded = Math.ceil(amount / roundingFactor) * roundingFactor;\n\tconst decimals = (roundingFactor.toString().split('.')[1] || '').length;\n\treturn Number(rounded.toFixed(decimals));\n};\n\nexport const convertToSecondarySync = (price: number, exchangeRate: number, roundTo: number) => {\n\tif (price == 0) return 0;\n\tif (price == null) return null;\n\tconst amount = price * exchangeRate;\n\tif (!roundTo) return amount;\n\treturn roundCurrencySync(amount, roundTo);\n};"]}
|