@lyxa.ai/types 1.1.38 → 1.1.39

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.1.38
25
+ Version: 1.1.39
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.1.38",
3
+ "version": "1.1.39",
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",
@@ -1,2 +1,5 @@
1
+ export declare const BaseCurrencyRoundTo = 0.01;
2
+ export declare const SecondaryCurrencyRoundTo = 1000;
1
3
  export declare const roundCurrencySync: (amount: number, roundingFactor: number) => number;
2
- export declare const convertToSecondarySync: (price: number, exchangeRate: number, roundTo: number) => number | null;
4
+ export declare const roundBaseCurrency: (amount: number) => number;
5
+ export declare const roundSecondaryCurrency: (amount: number) => number;
@@ -1,23 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertToSecondarySync = exports.roundCurrencySync = void 0;
3
+ exports.roundSecondaryCurrency = exports.roundBaseCurrency = exports.roundCurrencySync = exports.SecondaryCurrencyRoundTo = exports.BaseCurrencyRoundTo = void 0;
4
+ exports.BaseCurrencyRoundTo = 0.01;
5
+ exports.SecondaryCurrencyRoundTo = 1000;
4
6
  const roundCurrencySync = (amount, roundingFactor) => {
5
- if (amount == 0)
7
+ if (typeof amount !== 'number' ||
8
+ isNaN(amount) ||
9
+ typeof roundingFactor !== 'number' ||
10
+ roundingFactor <= 0 ||
11
+ amount === 0) {
6
12
  return 0;
7
- const rounded = Math.ceil(amount / roundingFactor) * roundingFactor;
13
+ }
8
14
  const decimals = (roundingFactor.toString().split('.')[1] || '').length;
15
+ const rounded = Math.round(amount / roundingFactor) * roundingFactor;
9
16
  return Number(rounded.toFixed(decimals));
10
17
  };
11
18
  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);
19
+ const roundBaseCurrency = (amount) => {
20
+ return (0, exports.roundCurrencySync)(amount, exports.BaseCurrencyRoundTo);
21
+ };
22
+ exports.roundBaseCurrency = roundBaseCurrency;
23
+ const roundSecondaryCurrency = (amount) => {
24
+ return (0, exports.roundCurrencySync)(amount, exports.SecondaryCurrencyRoundTo);
21
25
  };
22
- exports.convertToSecondarySync = convertToSecondarySync;
26
+ exports.roundSecondaryCurrency = roundSecondaryCurrency;
23
27
  //# sourceMappingURL=currency.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"currency.js","sourceRoot":"/","sources":["utilities/shared/currency.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};"]}
1
+ {"version":3,"file":"currency.js","sourceRoot":"/","sources":["utilities/shared/currency.ts"],"names":[],"mappings":";;;AACa,QAAA,mBAAmB,GAAG,IAAI,CAAC;AAC3B,QAAA,wBAAwB,GAAG,IAAI,CAAC;AAGtC,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAE,cAAsB,EAAU,EAAE;IACnF,IACC,OAAO,MAAM,KAAK,QAAQ;QAC1B,KAAK,CAAC,MAAM,CAAC;QACb,OAAO,cAAc,KAAK,QAAQ;QAClC,cAAc,IAAI,CAAC;QACnB,MAAM,KAAK,CAAC,EACX,CAAC;QACF,OAAO,CAAC,CAAC;IACV,CAAC;IAED,MAAM,QAAQ,GAAG,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IACxE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,cAAc,CAAC,GAAG,cAAc,CAAC;IAErE,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC;AAfW,QAAA,iBAAiB,qBAe5B;AAGK,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAU,EAAE;IAC3D,OAAO,IAAA,yBAAiB,EAAC,MAAM,EAAE,2BAAmB,CAAC,CAAC;AACvD,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AAEK,MAAM,sBAAsB,GAAG,CAAC,MAAc,EAAU,EAAE;IAChE,OAAO,IAAA,yBAAiB,EAAC,MAAM,EAAE,gCAAwB,CAAC,CAAC;AAC5D,CAAC,CAAC;AAFW,QAAA,sBAAsB,0BAEjC","sourcesContent":["// === Currency Rounding Constants ===\nexport const BaseCurrencyRoundTo = 0.01;\nexport const SecondaryCurrencyRoundTo = 1000;\n\n// === Safely rounds a number to the nearest rounding unit ===\nexport const roundCurrencySync = (amount: number, roundingFactor: number): number => {\n\tif (\n\t\ttypeof amount !== 'number' ||\n\t\tisNaN(amount) ||\n\t\ttypeof roundingFactor !== 'number' ||\n\t\troundingFactor <= 0 ||\n\t\tamount === 0\n\t) {\n\t\treturn 0;\n\t}\n\n\tconst decimals = (roundingFactor.toString().split('.')[1] || '').length;\n\tconst rounded = Math.round(amount / roundingFactor) * roundingFactor;\n\n\treturn Number(rounded.toFixed(decimals));\n};\n\n// === Specific rounding functions for base and secondary currencies ===\nexport const roundBaseCurrency = (amount: number): number => {\n\treturn roundCurrencySync(amount, BaseCurrencyRoundTo);\n};\n\nexport const roundSecondaryCurrency = (amount: number): number => {\n\treturn roundCurrencySync(amount, SecondaryCurrencyRoundTo);\n};\n"]}