@stll/money 0.2.2 → 0.3.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.
package/dist/index.d.ts CHANGED
@@ -110,6 +110,12 @@ export type ProrateHourlyCentsInput = {
110
110
  hourlyRateCents: CentsAmount;
111
111
  };
112
112
  export declare const prorateHourlyCents: ({ billedMinutes, hourlyRateCents }: ProrateHourlyCentsInput) => CentsAmount;
113
+ type TimeEntryAmountInput = {
114
+ billedMinutes: number;
115
+ rateAtEntry: CentsAmount;
116
+ noCharge: boolean;
117
+ };
118
+ export declare const timeEntryAmount: (entry: TimeEntryAmountInput) => CentsAmount;
113
119
  export type ApplyMarkupCentsInput = {
114
120
  amountCents: CentsAmount;
115
121
  markupPercent: number;
package/dist/index.js CHANGED
@@ -209,15 +209,21 @@ 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
  };
215
+ const timeEntryAmount = (entry) => entry.noCharge ? cents(0) : prorateHourlyCents({
216
+ billedMinutes: entry.billedMinutes,
217
+ hourlyRateCents: entry.rateAtEntry
218
+ });
214
219
  const applyMarkupCents = ({ amountCents, markupPercent }) => {
215
220
  assertNonNegativeInteger("amountCents", amountCents);
216
221
  assertNonNegativeInteger("markupPercent", markupPercent);
217
- return cents(Math.floor((amountCents * (100 + markupPercent) + 50) / 100));
222
+ const product = BigInt(amountCents) * (100n + BigInt(markupPercent));
223
+ return cents(Number((product + 50n) / 100n));
218
224
  };
219
225
  function assertNonNegativeInteger(name, value) {
220
- if (!Number.isFinite(value) || !Number.isInteger(value) || value < 0) panic(`${name} must be a finite non-negative integer`);
226
+ if (!Number.isSafeInteger(value) || value < 0) panic(`${name} must be a finite non-negative integer within the safe range`);
221
227
  }
222
228
  const isCurrencyCents = (amount, currency) => currency !== "" && isMinorUnitAmount(amount);
223
229
  /**
@@ -275,4 +281,4 @@ var MoneyTotals = class {
275
281
  }
276
282
  };
277
283
  //#endregion
278
- export { MoneyTotals, addCents, applyMarkupCents, cents, currencyCents, currencyMinorUnitDigits, formatMoneyCents, prorateHourlyCents, toMajorUnits, toMinorUnits, tryToMinorUnits, unsafeCents };
284
+ export { MoneyTotals, addCents, applyMarkupCents, cents, currencyCents, currencyMinorUnitDigits, formatMoneyCents, prorateHourlyCents, timeEntryAmount, toMajorUnits, toMinorUnits, tryToMinorUnits, unsafeCents };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/money",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
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"