@stackedapp/utils 2.50.0 → 2.52.0

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.
@@ -18,6 +18,15 @@ declare const currency: {
18
18
  roundUpDecimalPlaces(val: number, decimalPlaces: number): number;
19
19
  roundDecimalPlaces(val: number, decimalPlaces: number): number;
20
20
  roundDownDecimalPlaces(val: number, decimalPlaces: number): number;
21
+ /**
22
+ * Round a reward amount based on reward kind.
23
+ * - loyalty_currency: round down to min using the currency's decimal places
24
+ * - coins: round down to min at 1 decimal place
25
+ * - all others: round down to min at 0 decimal places (integer)
26
+ *
27
+ * "Round down to min" means floor, but if the result would be 0, return the smallest unit instead.
28
+ */
29
+ roundRewardAmount(amount: number, rewardKind: string, roundDecimalPlaces?: number): number;
21
30
  };
22
31
  export default currency;
23
32
  //# sourceMappingURL=currency.d.ts.map
package/dist/currency.js CHANGED
@@ -50,6 +50,20 @@ const currency = {
50
50
  const factor = 10 ** decimalPlaces;
51
51
  return Math.floor(val * factor) / factor;
52
52
  },
53
+ /**
54
+ * Round a reward amount based on reward kind.
55
+ * - loyalty_currency: round down to min using the currency's decimal places
56
+ * - coins: round down to min at 1 decimal place
57
+ * - all others: round down to min at 0 decimal places (integer)
58
+ *
59
+ * "Round down to min" means floor, but if the result would be 0, return the smallest unit instead.
60
+ */
61
+ roundRewardAmount(amount, rewardKind, roundDecimalPlaces) {
62
+ if (rewardKind === 'loyalty_currency') {
63
+ return currency.roundDownToMin(amount, roundDecimalPlaces ?? 0);
64
+ }
65
+ return currency.roundDownToMin(amount, rewardKind === 'coins' ? 1 : 0);
66
+ },
53
67
  };
54
68
  exports.default = currency;
55
69
  //# sourceMappingURL=currency.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackedapp/utils",
3
- "version": "2.50.0",
3
+ "version": "2.52.0",
4
4
  "description": "Public utilities for Stacked platform SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",