@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
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.0.305
25
+ Version: 1.0.306
26
26
 
27
27
  ## Dependencies
28
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.0.305",
3
+ "version": "1.0.306",
4
4
  "description": "Lyxa type definitions and validation schemas for both frontend and backend",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -0,0 +1,2 @@
1
+ export declare const roundCurrencySync: (amount: number, roundingFactor: number) => number;
2
+ export declare const convertToSecondarySync: (price: number, exchangeRate: number, roundTo: number) => number | null;
@@ -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};"]}