@stll/money 0.2.2 → 0.2.3

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.
Files changed (2) hide show
  1. package/dist/index.js +5 -3
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -209,15 +209,17 @@ const formatMoneyCents = ({ amountCents, currency, locale, fractionDigits }) =>
209
209
  const prorateHourlyCents = ({ billedMinutes, hourlyRateCents }) => {
210
210
  assertNonNegativeInteger("billedMinutes", billedMinutes);
211
211
  assertNonNegativeInteger("hourlyRateCents", hourlyRateCents);
212
- return cents(Math.floor((billedMinutes * hourlyRateCents + 30) / 60));
212
+ const product = BigInt(billedMinutes) * BigInt(hourlyRateCents);
213
+ return cents(Number((product + 30n) / 60n));
213
214
  };
214
215
  const applyMarkupCents = ({ amountCents, markupPercent }) => {
215
216
  assertNonNegativeInteger("amountCents", amountCents);
216
217
  assertNonNegativeInteger("markupPercent", markupPercent);
217
- return cents(Math.floor((amountCents * (100 + markupPercent) + 50) / 100));
218
+ const product = BigInt(amountCents) * (100n + BigInt(markupPercent));
219
+ return cents(Number((product + 50n) / 100n));
218
220
  };
219
221
  function assertNonNegativeInteger(name, value) {
220
- if (!Number.isFinite(value) || !Number.isInteger(value) || value < 0) panic(`${name} must be a finite non-negative integer`);
222
+ if (!Number.isSafeInteger(value) || value < 0) panic(`${name} must be a finite non-negative integer within the safe range`);
221
223
  }
222
224
  const isCurrencyCents = (amount, currency) => currency !== "" && isMinorUnitAmount(amount);
223
225
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/money",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Branded minor-unit monetary amounts and currency-safe billing arithmetic.",
5
5
  "keywords": [
6
6
  "billing",
@@ -40,7 +40,7 @@
40
40
  "pack:dry-run": "bun pm pack --dry-run",
41
41
  "test": "bun test src",
42
42
  "typecheck": "bun ../../packages/scripts/src/tsc-native.ts --noEmit",
43
- "lint": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --report-unused-disable-directives-severity=error --type-aware packages/money",
43
+ "lint": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --report-unused-disable-directives-severity=error --type-aware --type-check packages/money",
44
44
  "lint:fix": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --type-aware --fix packages/money",
45
45
  "format": "bun ../../scripts/run-oxfmt.ts .",
46
46
  "prepack": "bun run build"