MCPcopy Index your code
hub / github.com/OpenPipe/OpenPipe / calculateSpendingsWithCredits

Function calculateSpendingsWithCredits

app/src/utils/billing.ts:1–23  ·  view source on GitHub ↗
(spend: number, credits: number)

Source from the content-addressed store, hash-verified

1export function calculateSpendingsWithCredits(spend: number, credits: number) {
2 const totalSpent = calculateTotalSpent(spend, credits);
3 const creditsUsed = calculateCreditsUsed(spend, credits);
4 const remainingCredits = calculateRemainingCredits(spend, credits);
5
6 return { totalSpent, creditsUsed, remainingCredits };
7
8 function calculateTotalSpent(spend: number, credits: number) {
9 const totalSpent = spend - credits;
10
11 return totalSpent > 0 ? totalSpent : 0;
12 }
13
14 function calculateCreditsUsed(spend: number, credits: number) {
15 return spend - credits < 0 ? spend : credits;
16 }
17
18 function calculateRemainingCredits(spend: number, credits: number) {
19 const remainingCredits = credits - spend;
20
21 return remainingCredits > 0 ? remainingCredits : 0;
22 }
23}

Callers 2

UsageFunction · 0.90
createInvoiceFunction · 0.90

Calls 3

calculateTotalSpentFunction · 0.85
calculateCreditsUsedFunction · 0.85

Tested by

no test coverage detected