@helpu/headless-budget-calculator 1.0.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.
@@ -0,0 +1,17 @@
1
+ # Commercial Licensing
2
+
3
+ This software is available for permitted non-commercial use under the PolyForm Noncommercial License 1.0.0.
4
+
5
+ Commercial use requires a separate license from Omisai Technologies.
6
+
7
+ Organizations wishing to use this software in connection with a commercial product, service, platform, internal business activity, client engagement, SaaS offering, financial service, or other commercial activity should contact Omisai Technologies to discuss commercial licensing.
8
+
9
+ Commercial licensing revenue supports the HelpU Finance mission of creating freely accessible financial tools, educational resources, and technology for the public.
10
+
11
+ ## Commercial Licensing Contact
12
+
13
+ Commercial licensing: Please contact Omisai Technologies through its [official website](https://omisai.com/licensing).
14
+
15
+ Copyright (c) 2026 Omisai Technologies.
16
+
17
+ HelpU Finance is a project and brand of Omisai Technologies.
package/LICENSE ADDED
@@ -0,0 +1,64 @@
1
+ Required Notice: Copyright (c) 2026 Omisai Technologies
2
+ Required Notice: HelpU Finance is a project and brand of Omisai Technologies.
3
+ Required Notice: Commercial licensing is available separately from Omisai Technologies.
4
+
5
+ # PolyForm Noncommercial License 1.0.0
6
+
7
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
8
+
9
+ ## Acceptance
10
+
11
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
12
+ ## Copyright License
13
+
14
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
15
+ ## Distribution License
16
+
17
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
18
+ ## Notices
19
+
20
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
21
+
22
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
23
+ ## Changes and New Works License
24
+
25
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
26
+ ## Patent License
27
+
28
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
29
+ ## Noncommercial Purposes
30
+
31
+ Any noncommercial purpose is a permitted purpose.
32
+ ## Personal Uses
33
+
34
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
35
+ ## Noncommercial Organizations
36
+
37
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
38
+
39
+ ## Fair Use
40
+
41
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
42
+ ## No Other Rights
43
+
44
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
45
+ ## Patent Defense
46
+
47
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
48
+ ## Violations
49
+
50
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
51
+ ## No Liability
52
+
53
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
54
+ ## Definitions
55
+
56
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
57
+
58
+ **You** refers to the individual or entity agreeing to these terms.
59
+
60
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
61
+
62
+ **Your licenses** are all the licenses granted to you for the software under these terms.
63
+
64
+ **Use** means anything you do with the software requiring one of your licenses.
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ <p align="center">
2
+ <a href="https://github.com/helpufinance/helpu.finance">
3
+ <img src="https://raw.githubusercontent.com/helpufinance/.github/refs/heads/main/profile/assets/helpu_finance.png" alt="HelpU Finance" width="260">
4
+ </a>
5
+ </p>
6
+
7
+ # Headless Budget Calculator
8
+
9
+ A headless, framework-agnostic budget calculator with income and expense categorization, savings goals, and budget analysis.
10
+
11
+ ## What is HelpU Finance?
12
+
13
+ HelpU Finance is a free, privacy-first platform with financial tools and educational resources. No tracking, no data collection.
14
+
15
+ We believe that financial literacy should be accessible to everyone.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @helpu/headless-budget-calculator
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```ts
26
+ import { calculateBudget, createBudgetItem } from '@helpu/headless-budget-calculator'
27
+
28
+ const result = calculateBudget({
29
+ currency: 'USD',
30
+ items: [
31
+ createBudgetItem({
32
+ name: 'Salary',
33
+ amount: 5000,
34
+ type: 'income',
35
+ category: 'salary',
36
+ }),
37
+ createBudgetItem({
38
+ name: 'Rent',
39
+ amount: 1500,
40
+ type: 'expense',
41
+ category: 'housing',
42
+ isEssential: true,
43
+ }),
44
+ ],
45
+ })
46
+
47
+ if (result.success) {
48
+ console.log(result.data.monthlySurplus)
49
+ console.log(result.data.recommendations)
50
+ } else {
51
+ console.error(result.error.message)
52
+ }
53
+ ```
54
+
55
+ Amounts are normalized using each item’s `frequency`. The result includes monthly and annual totals, savings rate, category breakdowns, budget health, and recommendations.
56
+
57
+ ## Testing
58
+
59
+ Install the repository dependencies and run the test suite with:
60
+
61
+ ```bash
62
+ npm test
63
+ ```
64
+
65
+ ## Contributing
66
+
67
+ Contributions are welcome. Please read the [contribution guidelines](https://docs.omisai.com/contribution-guidelines) before opening a pull request.
68
+
69
+ ## Sponsor
70
+
71
+ Support HelpU Finance through [GitHub Sponsors](https://github.com/sponsors/helpufinance).
72
+
73
+ ## License
74
+
75
+ This project is available for permitted non-commercial use under the **PolyForm Noncommercial License 1.0.0**.
76
+
77
+ Personal learning, education, research, experimentation, and other uses permitted by the PolyForm Noncommercial License are welcome.
78
+
79
+ **Commercial use requires a separate license from Omisai Technologies.**
80
+
81
+ Commercial licensing helps fund the HelpU Finance mission of creating freely accessible financial tools, educational resources, and technology.
82
+
83
+ For commercial licensing, see [`COMMERCIAL-LICENSING.md`](./COMMERCIAL-LICENSING.md).
84
+
85
+ Copyright (c) 2026 Omisai Technologies.
86
+
87
+ HelpU Finance is a project and brand of Omisai Technologies.
@@ -0,0 +1,12 @@
1
+ import type { BudgetCalculationError, BudgetCalculationResult, BudgetFrequency, BudgetInput, BudgetItem } from './types';
2
+ export declare function toMonthlyAmount(amount: number, frequency: BudgetFrequency): number;
3
+ export declare function toAnnualAmount(amount: number, frequency: BudgetFrequency): number;
4
+ export declare function validateBudgetInput(input: BudgetInput): BudgetCalculationError | null;
5
+ export declare function calculateBudget(input: BudgetInput): BudgetCalculationResult;
6
+ export declare function createBudgetItem(overrides: Partial<BudgetItem> & Pick<BudgetItem, 'name' | 'amount' | 'type' | 'category'>): BudgetItem;
7
+ export declare function get503020Breakdown(monthlyIncome: number): {
8
+ needs: number;
9
+ wants: number;
10
+ savings: number;
11
+ };
12
+ //# sourceMappingURL=calculator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculator.d.ts","sourceRoot":"","sources":["../src/calculator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,sBAAsB,EACtB,uBAAuB,EACvB,eAAe,EAEf,WAAW,EACX,UAAU,EAEX,MAAM,SAAS,CAAA;AAChB,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,GAAG,MAAM,CAiBlF;AACD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,GAAG,MAAM,CAiBjF;AACD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,sBAAsB,GAAG,IAAI,CAwBrF;AA2GD,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,GAAG,uBAAuB,CAuE3E;AACD,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC,GACzF,UAAU,CAoBZ;AACD,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG;IACzD,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;CAChB,CAMA"}
package/dist/index.cjs ADDED
@@ -0,0 +1,325 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/types.ts
3
+ const EXPENSE_CATEGORIES = {
4
+ housing: {
5
+ key: "housing",
6
+ label: "Housing",
7
+ icon: "🏠",
8
+ suggestedPercent: 30
9
+ },
10
+ transportation: {
11
+ key: "transportation",
12
+ label: "Transportation",
13
+ icon: "🚗",
14
+ suggestedPercent: 10
15
+ },
16
+ food: {
17
+ key: "food",
18
+ label: "Food & Groceries",
19
+ icon: "🛒",
20
+ suggestedPercent: 12
21
+ },
22
+ utilities: {
23
+ key: "utilities",
24
+ label: "Utilities",
25
+ icon: "💡",
26
+ suggestedPercent: 5
27
+ },
28
+ healthcare: {
29
+ key: "healthcare",
30
+ label: "Healthcare",
31
+ icon: "🏥",
32
+ suggestedPercent: 5
33
+ },
34
+ insurance: {
35
+ key: "insurance",
36
+ label: "Insurance",
37
+ icon: "🛡️",
38
+ suggestedPercent: 5
39
+ },
40
+ savings: {
41
+ key: "savings",
42
+ label: "Savings & Investments",
43
+ icon: "💰",
44
+ suggestedPercent: 20
45
+ },
46
+ debt: {
47
+ key: "debt",
48
+ label: "Debt Payments",
49
+ icon: "💳",
50
+ suggestedPercent: 5
51
+ },
52
+ personal: {
53
+ key: "personal",
54
+ label: "Personal Care",
55
+ icon: "🧴"
56
+ },
57
+ entertainment: {
58
+ key: "entertainment",
59
+ label: "Entertainment",
60
+ icon: "🎬"
61
+ },
62
+ education: {
63
+ key: "education",
64
+ label: "Education",
65
+ icon: "📚"
66
+ },
67
+ clothing: {
68
+ key: "clothing",
69
+ label: "Clothing",
70
+ icon: "👕"
71
+ },
72
+ gifts: {
73
+ key: "gifts",
74
+ label: "Gifts & Donations",
75
+ icon: "🎁"
76
+ },
77
+ subscriptions: {
78
+ key: "subscriptions",
79
+ label: "Subscriptions",
80
+ icon: "📱"
81
+ },
82
+ other: {
83
+ key: "other",
84
+ label: "Other",
85
+ icon: "📦"
86
+ }
87
+ };
88
+ const INCOME_CATEGORIES = {
89
+ salary: {
90
+ key: "salary",
91
+ label: "Salary / Wages",
92
+ icon: "💼"
93
+ },
94
+ freelance: {
95
+ key: "freelance",
96
+ label: "Freelance / Contract",
97
+ icon: "💻"
98
+ },
99
+ investments: {
100
+ key: "investments",
101
+ label: "Investment Returns",
102
+ icon: "📈"
103
+ },
104
+ rental: {
105
+ key: "rental",
106
+ label: "Rental Income",
107
+ icon: "🏢"
108
+ },
109
+ business: {
110
+ key: "business",
111
+ label: "Business Income",
112
+ icon: "🏪"
113
+ },
114
+ pension: {
115
+ key: "pension",
116
+ label: "Pension",
117
+ icon: "🧓"
118
+ },
119
+ "social-benefits": {
120
+ key: "social-benefits",
121
+ label: "Social Benefits",
122
+ icon: "🏛️"
123
+ },
124
+ "gifts-received": {
125
+ key: "gifts-received",
126
+ label: "Gifts Received",
127
+ icon: "🎀"
128
+ },
129
+ other: {
130
+ key: "other",
131
+ label: "Other Income",
132
+ icon: "💵"
133
+ }
134
+ };
135
+ //#endregion
136
+ //#region src/calculator.ts
137
+ function toMonthlyAmount(amount, frequency) {
138
+ switch (frequency) {
139
+ case "weekly": return amount * (52 / 12);
140
+ case "biweekly": return amount * (26 / 12);
141
+ case "monthly": return amount;
142
+ case "quarterly": return amount / 3;
143
+ case "annually": return amount / 12;
144
+ case "one-time": return amount / 12;
145
+ default: return amount;
146
+ }
147
+ }
148
+ function toAnnualAmount(amount, frequency) {
149
+ switch (frequency) {
150
+ case "weekly": return amount * 52;
151
+ case "biweekly": return amount * 26;
152
+ case "monthly": return amount * 12;
153
+ case "quarterly": return amount * 4;
154
+ case "annually": return amount;
155
+ case "one-time": return amount;
156
+ default: return amount * 12;
157
+ }
158
+ }
159
+ function validateBudgetInput(input) {
160
+ if (!input.items || input.items.length === 0) return {
161
+ code: "NO_ITEMS",
162
+ message: "At least one budget item is required"
163
+ };
164
+ if (!input.items.some((item) => item.type === "income")) return {
165
+ code: "NO_INCOME",
166
+ message: "At least one income source is required"
167
+ };
168
+ for (const item of input.items) if (typeof item.amount !== "number" || isNaN(item.amount) || item.amount < 0) return {
169
+ code: "INVALID_AMOUNT",
170
+ message: `Invalid amount for "${item.name}": must be a non-negative number`,
171
+ field: item.id
172
+ };
173
+ return null;
174
+ }
175
+ function calculateBreakdowns(items, type, total) {
176
+ const categoryMap = /* @__PURE__ */ new Map();
177
+ for (const item of items) {
178
+ if (item.type !== type) continue;
179
+ const monthlyAmount = toMonthlyAmount(item.amount, item.frequency);
180
+ const existing = categoryMap.get(item.category) || {
181
+ amount: 0,
182
+ count: 0
183
+ };
184
+ categoryMap.set(item.category, {
185
+ amount: existing.amount + monthlyAmount,
186
+ count: existing.count + 1
187
+ });
188
+ }
189
+ return Array.from(categoryMap.entries()).map(([category, data]) => ({
190
+ category,
191
+ amount: parseFloat(data.amount.toFixed(2)),
192
+ percentage: total > 0 ? parseFloat((data.amount / total * 100).toFixed(1)) : 0,
193
+ itemCount: data.count
194
+ })).sort((a, b) => b.amount - a.amount);
195
+ }
196
+ function determineBudgetHealth(savingsRate, essentialRatio, monthlySurplus) {
197
+ let score = 50;
198
+ if (savingsRate >= 20) score += 30;
199
+ else if (savingsRate >= 15) score += 25;
200
+ else if (savingsRate >= 10) score += 15;
201
+ else if (savingsRate >= 5) score += 5;
202
+ else if (savingsRate < 0) score -= 20;
203
+ if (essentialRatio <= 50) score += 20;
204
+ else if (essentialRatio <= 60) score += 10;
205
+ else if (essentialRatio <= 70) score += 0;
206
+ else if (essentialRatio <= 80) score -= 10;
207
+ else score -= 20;
208
+ if (monthlySurplus > 0) score += 5;
209
+ else score -= 15;
210
+ score = Math.max(0, Math.min(100, score));
211
+ let status;
212
+ if (score >= 80) status = "excellent";
213
+ else if (score >= 65) status = "good";
214
+ else if (score >= 45) status = "fair";
215
+ else if (score >= 25) status = "poor";
216
+ else status = "critical";
217
+ return {
218
+ status,
219
+ score
220
+ };
221
+ }
222
+ function generateRecommendations(savingsRate, essentialRatio, monthlySurplus, _totalIncome, savingsGoalPercent, savingsGoalMet) {
223
+ const recommendations = [];
224
+ if (monthlySurplus < 0) recommendations.push("Your expenses exceed your income. Review discretionary spending for areas to cut back.");
225
+ if (savingsRate < 10) recommendations.push("Aim to save at least 10-20% of your income. Start small and gradually increase.");
226
+ if (essentialRatio > 70) recommendations.push("Essential expenses are consuming over 70% of your income. Look for ways to reduce fixed costs like housing or transportation.");
227
+ if (!savingsGoalMet && savingsGoalPercent > 0) recommendations.push(`You're not meeting your ${savingsGoalPercent}% savings goal. Consider reducing discretionary spending.`);
228
+ if (savingsRate >= 20 && essentialRatio <= 50) recommendations.push("Great financial health! Consider investing your surplus or building an emergency fund.");
229
+ if (monthlySurplus > 0 && savingsRate < 20) recommendations.push("You have a surplus — consider automating transfers to a savings or investment account.");
230
+ if (recommendations.length === 0) recommendations.push("Your budget looks balanced. Keep monitoring and adjusting as your financial situation changes.");
231
+ return recommendations;
232
+ }
233
+ function calculateBudget(input) {
234
+ const validationError = validateBudgetInput(input);
235
+ if (validationError) return {
236
+ success: false,
237
+ error: validationError
238
+ };
239
+ const { items, savingsGoalPercent = 20, emergencyFundMonths = 6 } = input;
240
+ let totalMonthlyIncome = 0;
241
+ let totalMonthlyExpenses = 0;
242
+ let essentialExpenses = 0;
243
+ let discretionaryExpenses = 0;
244
+ for (const item of items) {
245
+ const monthlyAmount = toMonthlyAmount(item.amount, item.frequency);
246
+ if (item.type === "income") totalMonthlyIncome += monthlyAmount;
247
+ else {
248
+ totalMonthlyExpenses += monthlyAmount;
249
+ if (item.isEssential) essentialExpenses += monthlyAmount;
250
+ else discretionaryExpenses += monthlyAmount;
251
+ }
252
+ }
253
+ const monthlySurplus = totalMonthlyIncome - totalMonthlyExpenses;
254
+ const annualIncome = totalMonthlyIncome * 12;
255
+ const annualExpenses = totalMonthlyExpenses * 12;
256
+ const annualSurplus = monthlySurplus * 12;
257
+ const savingsRate = totalMonthlyIncome > 0 ? monthlySurplus / totalMonthlyIncome * 100 : 0;
258
+ const targetSavingsAmount = totalMonthlyIncome * savingsGoalPercent / 100;
259
+ const savingsGoalMet = monthlySurplus >= targetSavingsAmount;
260
+ const essentialRatio = totalMonthlyIncome > 0 ? essentialExpenses / totalMonthlyIncome * 100 : 0;
261
+ const emergencyFundTarget = totalMonthlyExpenses * emergencyFundMonths;
262
+ const monthsToEmergencyFund = monthlySurplus > 0 ? Math.ceil(emergencyFundTarget / monthlySurplus) : null;
263
+ const expenseBreakdown = calculateBreakdowns(items, "expense", totalMonthlyExpenses);
264
+ const incomeBreakdown = calculateBreakdowns(items, "income", totalMonthlyIncome);
265
+ const { status: healthStatus, score: healthScore } = determineBudgetHealth(savingsRate, essentialRatio, monthlySurplus);
266
+ const recommendations = generateRecommendations(savingsRate, essentialRatio, monthlySurplus, totalMonthlyIncome, savingsGoalPercent, savingsGoalMet);
267
+ return {
268
+ success: true,
269
+ data: {
270
+ totalMonthlyIncome: parseFloat(totalMonthlyIncome.toFixed(2)),
271
+ totalMonthlyExpenses: parseFloat(totalMonthlyExpenses.toFixed(2)),
272
+ monthlySurplus: parseFloat(monthlySurplus.toFixed(2)),
273
+ annualIncome: parseFloat(annualIncome.toFixed(2)),
274
+ annualExpenses: parseFloat(annualExpenses.toFixed(2)),
275
+ annualSurplus: parseFloat(annualSurplus.toFixed(2)),
276
+ savingsRate: parseFloat(savingsRate.toFixed(1)),
277
+ savingsGoalMet,
278
+ targetSavingsAmount: parseFloat(targetSavingsAmount.toFixed(2)),
279
+ essentialExpenses: parseFloat(essentialExpenses.toFixed(2)),
280
+ discretionaryExpenses: parseFloat(discretionaryExpenses.toFixed(2)),
281
+ essentialRatio: parseFloat(essentialRatio.toFixed(1)),
282
+ expenseBreakdown,
283
+ incomeBreakdown,
284
+ healthStatus,
285
+ healthScore,
286
+ emergencyFundTarget: parseFloat(emergencyFundTarget.toFixed(2)),
287
+ monthsToEmergencyFund,
288
+ recommendations
289
+ }
290
+ };
291
+ }
292
+ function createBudgetItem(overrides) {
293
+ return {
294
+ id: crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`,
295
+ frequency: "monthly",
296
+ isEssential: overrides.type === "expense" ? [
297
+ "housing",
298
+ "food",
299
+ "utilities",
300
+ "healthcare",
301
+ "insurance",
302
+ "transportation",
303
+ "debt"
304
+ ].includes(overrides.category) : false,
305
+ ...overrides
306
+ };
307
+ }
308
+ function get503020Breakdown(monthlyIncome) {
309
+ return {
310
+ needs: parseFloat((monthlyIncome * .5).toFixed(2)),
311
+ wants: parseFloat((monthlyIncome * .3).toFixed(2)),
312
+ savings: parseFloat((monthlyIncome * .2).toFixed(2))
313
+ };
314
+ }
315
+ //#endregion
316
+ exports.EXPENSE_CATEGORIES = EXPENSE_CATEGORIES;
317
+ exports.INCOME_CATEGORIES = INCOME_CATEGORIES;
318
+ exports.calculateBudget = calculateBudget;
319
+ exports.createBudgetItem = createBudgetItem;
320
+ exports.get503020Breakdown = get503020Breakdown;
321
+ exports.toAnnualAmount = toAnnualAmount;
322
+ exports.toMonthlyAmount = toMonthlyAmount;
323
+ exports.validateBudgetInput = validateBudgetInput;
324
+
325
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/types.ts","../src/calculator.ts"],"sourcesContent":["export type BudgetCategoryType = 'income' | 'expense'\nexport type ExpenseCategory =\n | 'housing'\n | 'transportation'\n | 'food'\n | 'utilities'\n | 'healthcare'\n | 'insurance'\n | 'savings'\n | 'debt'\n | 'personal'\n | 'entertainment'\n | 'education'\n | 'clothing'\n | 'gifts'\n | 'subscriptions'\n | 'other'\nexport type IncomeCategory =\n | 'salary'\n | 'freelance'\n | 'investments'\n | 'rental'\n | 'business'\n | 'pension'\n | 'social-benefits'\n | 'gifts-received'\n | 'other'\nexport type BudgetFrequency =\n | 'monthly'\n | 'weekly'\n | 'biweekly'\n | 'quarterly'\n | 'annually'\n | 'one-time'\nexport interface BudgetItem {\n id: string\n name: string\n amount: number\n type: BudgetCategoryType\n category: ExpenseCategory | IncomeCategory\n frequency: BudgetFrequency\n isEssential: boolean\n}\nexport interface BudgetInput {\n items: BudgetItem[]\n currency?: string\n savingsGoalPercent?: number\n emergencyFundMonths?: number\n}\nexport interface CategoryBreakdown {\n category: string\n amount: number\n percentage: number\n itemCount: number\n}\nexport type BudgetHealthStatus = 'excellent' | 'good' | 'fair' | 'poor' | 'critical'\nexport interface BudgetAnalysis {\n totalMonthlyIncome: number\n totalMonthlyExpenses: number\n monthlySurplus: number\n annualIncome: number\n annualExpenses: number\n annualSurplus: number\n savingsRate: number\n savingsGoalMet: boolean\n targetSavingsAmount: number\n essentialExpenses: number\n discretionaryExpenses: number\n essentialRatio: number\n expenseBreakdown: CategoryBreakdown[]\n incomeBreakdown: CategoryBreakdown[]\n healthStatus: BudgetHealthStatus\n healthScore: number\n emergencyFundTarget: number\n monthsToEmergencyFund: number | null\n recommendations: string[]\n}\nexport interface BudgetCalculationError {\n code: 'NO_ITEMS' | 'NO_INCOME' | 'INVALID_AMOUNT' | 'INVALID_INPUT'\n message: string\n field?: string\n}\nexport type BudgetCalculationResult =\n | {\n success: true\n data: BudgetAnalysis\n }\n | {\n success: false\n error: BudgetCalculationError\n }\nexport interface CategoryConfig {\n key: string\n label: string\n icon: string\n suggestedPercent?: number\n}\nexport const EXPENSE_CATEGORIES: Record<ExpenseCategory, CategoryConfig> = {\n housing: { key: 'housing', label: 'Housing', icon: '🏠', suggestedPercent: 30 },\n transportation: {\n key: 'transportation',\n label: 'Transportation',\n icon: '🚗',\n suggestedPercent: 10,\n },\n food: { key: 'food', label: 'Food & Groceries', icon: '🛒', suggestedPercent: 12 },\n utilities: { key: 'utilities', label: 'Utilities', icon: '💡', suggestedPercent: 5 },\n healthcare: { key: 'healthcare', label: 'Healthcare', icon: '🏥', suggestedPercent: 5 },\n insurance: { key: 'insurance', label: 'Insurance', icon: '🛡️', suggestedPercent: 5 },\n savings: { key: 'savings', label: 'Savings & Investments', icon: '💰', suggestedPercent: 20 },\n debt: { key: 'debt', label: 'Debt Payments', icon: '💳', suggestedPercent: 5 },\n personal: { key: 'personal', label: 'Personal Care', icon: '🧴' },\n entertainment: { key: 'entertainment', label: 'Entertainment', icon: '🎬' },\n education: { key: 'education', label: 'Education', icon: '📚' },\n clothing: { key: 'clothing', label: 'Clothing', icon: '👕' },\n gifts: { key: 'gifts', label: 'Gifts & Donations', icon: '🎁' },\n subscriptions: { key: 'subscriptions', label: 'Subscriptions', icon: '📱' },\n other: { key: 'other', label: 'Other', icon: '📦' },\n}\nexport const INCOME_CATEGORIES: Record<IncomeCategory, CategoryConfig> = {\n salary: { key: 'salary', label: 'Salary / Wages', icon: '💼' },\n freelance: { key: 'freelance', label: 'Freelance / Contract', icon: '💻' },\n investments: { key: 'investments', label: 'Investment Returns', icon: '📈' },\n rental: { key: 'rental', label: 'Rental Income', icon: '🏢' },\n business: { key: 'business', label: 'Business Income', icon: '🏪' },\n pension: { key: 'pension', label: 'Pension', icon: '🧓' },\n 'social-benefits': { key: 'social-benefits', label: 'Social Benefits', icon: '🏛️' },\n 'gifts-received': { key: 'gifts-received', label: 'Gifts Received', icon: '🎀' },\n other: { key: 'other', label: 'Other Income', icon: '💵' },\n}\n","import type {\n BudgetAnalysis,\n BudgetCalculationError,\n BudgetCalculationResult,\n BudgetFrequency,\n BudgetHealthStatus,\n BudgetInput,\n BudgetItem,\n CategoryBreakdown,\n} from './types'\nexport function toMonthlyAmount(amount: number, frequency: BudgetFrequency): number {\n switch (frequency) {\n case 'weekly':\n return amount * (52 / 12)\n case 'biweekly':\n return amount * (26 / 12)\n case 'monthly':\n return amount\n case 'quarterly':\n return amount / 3\n case 'annually':\n return amount / 12\n case 'one-time':\n return amount / 12\n default:\n return amount\n }\n}\nexport function toAnnualAmount(amount: number, frequency: BudgetFrequency): number {\n switch (frequency) {\n case 'weekly':\n return amount * 52\n case 'biweekly':\n return amount * 26\n case 'monthly':\n return amount * 12\n case 'quarterly':\n return amount * 4\n case 'annually':\n return amount\n case 'one-time':\n return amount\n default:\n return amount * 12\n }\n}\nexport function validateBudgetInput(input: BudgetInput): BudgetCalculationError | null {\n if (!input.items || input.items.length === 0) {\n return {\n code: 'NO_ITEMS',\n message: 'At least one budget item is required',\n }\n }\n const hasIncome = input.items.some((item) => item.type === 'income')\n if (!hasIncome) {\n return {\n code: 'NO_INCOME',\n message: 'At least one income source is required',\n }\n }\n for (const item of input.items) {\n if (typeof item.amount !== 'number' || isNaN(item.amount) || item.amount < 0) {\n return {\n code: 'INVALID_AMOUNT',\n message: `Invalid amount for \"${item.name}\": must be a non-negative number`,\n field: item.id,\n }\n }\n }\n return null\n}\nfunction calculateBreakdowns(\n items: BudgetItem[],\n type: 'income' | 'expense',\n total: number,\n): CategoryBreakdown[] {\n const categoryMap = new Map<\n string,\n {\n amount: number\n count: number\n }\n >()\n for (const item of items) {\n if (item.type !== type) continue\n const monthlyAmount = toMonthlyAmount(item.amount, item.frequency)\n const existing = categoryMap.get(item.category) || { amount: 0, count: 0 }\n categoryMap.set(item.category, {\n amount: existing.amount + monthlyAmount,\n count: existing.count + 1,\n })\n }\n return Array.from(categoryMap.entries())\n .map(([category, data]) => ({\n category,\n amount: parseFloat(data.amount.toFixed(2)),\n percentage: total > 0 ? parseFloat(((data.amount / total) * 100).toFixed(1)) : 0,\n itemCount: data.count,\n }))\n .sort((a, b) => b.amount - a.amount)\n}\nfunction determineBudgetHealth(\n savingsRate: number,\n essentialRatio: number,\n monthlySurplus: number,\n): {\n status: BudgetHealthStatus\n score: number\n} {\n let score = 50\n if (savingsRate >= 20) score += 30\n else if (savingsRate >= 15) score += 25\n else if (savingsRate >= 10) score += 15\n else if (savingsRate >= 5) score += 5\n else if (savingsRate < 0) score -= 20\n if (essentialRatio <= 50) score += 20\n else if (essentialRatio <= 60) score += 10\n else if (essentialRatio <= 70) score += 0\n else if (essentialRatio <= 80) score -= 10\n else score -= 20\n if (monthlySurplus > 0) score += 5\n else score -= 15\n score = Math.max(0, Math.min(100, score))\n let status: BudgetHealthStatus\n if (score >= 80) status = 'excellent'\n else if (score >= 65) status = 'good'\n else if (score >= 45) status = 'fair'\n else if (score >= 25) status = 'poor'\n else status = 'critical'\n return { status, score }\n}\nfunction generateRecommendations(\n savingsRate: number,\n essentialRatio: number,\n monthlySurplus: number,\n _totalIncome: number,\n savingsGoalPercent: number,\n savingsGoalMet: boolean,\n): string[] {\n const recommendations: string[] = []\n if (monthlySurplus < 0) {\n recommendations.push(\n 'Your expenses exceed your income. Review discretionary spending for areas to cut back.',\n )\n }\n if (savingsRate < 10) {\n recommendations.push(\n 'Aim to save at least 10-20% of your income. Start small and gradually increase.',\n )\n }\n if (essentialRatio > 70) {\n recommendations.push(\n 'Essential expenses are consuming over 70% of your income. Look for ways to reduce fixed costs like housing or transportation.',\n )\n }\n if (!savingsGoalMet && savingsGoalPercent > 0) {\n recommendations.push(\n `You're not meeting your ${savingsGoalPercent}% savings goal. Consider reducing discretionary spending.`,\n )\n }\n if (savingsRate >= 20 && essentialRatio <= 50) {\n recommendations.push(\n 'Great financial health! Consider investing your surplus or building an emergency fund.',\n )\n }\n if (monthlySurplus > 0 && savingsRate < 20) {\n recommendations.push(\n 'You have a surplus — consider automating transfers to a savings or investment account.',\n )\n }\n if (recommendations.length === 0) {\n recommendations.push(\n 'Your budget looks balanced. Keep monitoring and adjusting as your financial situation changes.',\n )\n }\n return recommendations\n}\nexport function calculateBudget(input: BudgetInput): BudgetCalculationResult {\n const validationError = validateBudgetInput(input)\n if (validationError) {\n return { success: false, error: validationError }\n }\n const { items, savingsGoalPercent = 20, emergencyFundMonths = 6 } = input\n let totalMonthlyIncome = 0\n let totalMonthlyExpenses = 0\n let essentialExpenses = 0\n let discretionaryExpenses = 0\n for (const item of items) {\n const monthlyAmount = toMonthlyAmount(item.amount, item.frequency)\n if (item.type === 'income') {\n totalMonthlyIncome += monthlyAmount\n } else {\n totalMonthlyExpenses += monthlyAmount\n if (item.isEssential) {\n essentialExpenses += monthlyAmount\n } else {\n discretionaryExpenses += monthlyAmount\n }\n }\n }\n const monthlySurplus = totalMonthlyIncome - totalMonthlyExpenses\n const annualIncome = totalMonthlyIncome * 12\n const annualExpenses = totalMonthlyExpenses * 12\n const annualSurplus = monthlySurplus * 12\n const savingsRate = totalMonthlyIncome > 0 ? (monthlySurplus / totalMonthlyIncome) * 100 : 0\n const targetSavingsAmount = (totalMonthlyIncome * savingsGoalPercent) / 100\n const savingsGoalMet = monthlySurplus >= targetSavingsAmount\n const essentialRatio = totalMonthlyIncome > 0 ? (essentialExpenses / totalMonthlyIncome) * 100 : 0\n const emergencyFundTarget = totalMonthlyExpenses * emergencyFundMonths\n const monthsToEmergencyFund =\n monthlySurplus > 0 ? Math.ceil(emergencyFundTarget / monthlySurplus) : null\n const expenseBreakdown = calculateBreakdowns(items, 'expense', totalMonthlyExpenses)\n const incomeBreakdown = calculateBreakdowns(items, 'income', totalMonthlyIncome)\n const { status: healthStatus, score: healthScore } = determineBudgetHealth(\n savingsRate,\n essentialRatio,\n monthlySurplus,\n )\n const recommendations = generateRecommendations(\n savingsRate,\n essentialRatio,\n monthlySurplus,\n totalMonthlyIncome,\n savingsGoalPercent,\n savingsGoalMet,\n )\n const analysis: BudgetAnalysis = {\n totalMonthlyIncome: parseFloat(totalMonthlyIncome.toFixed(2)),\n totalMonthlyExpenses: parseFloat(totalMonthlyExpenses.toFixed(2)),\n monthlySurplus: parseFloat(monthlySurplus.toFixed(2)),\n annualIncome: parseFloat(annualIncome.toFixed(2)),\n annualExpenses: parseFloat(annualExpenses.toFixed(2)),\n annualSurplus: parseFloat(annualSurplus.toFixed(2)),\n savingsRate: parseFloat(savingsRate.toFixed(1)),\n savingsGoalMet,\n targetSavingsAmount: parseFloat(targetSavingsAmount.toFixed(2)),\n essentialExpenses: parseFloat(essentialExpenses.toFixed(2)),\n discretionaryExpenses: parseFloat(discretionaryExpenses.toFixed(2)),\n essentialRatio: parseFloat(essentialRatio.toFixed(1)),\n expenseBreakdown,\n incomeBreakdown,\n healthStatus,\n healthScore,\n emergencyFundTarget: parseFloat(emergencyFundTarget.toFixed(2)),\n monthsToEmergencyFund,\n recommendations,\n }\n return { success: true, data: analysis }\n}\nexport function createBudgetItem(\n overrides: Partial<BudgetItem> & Pick<BudgetItem, 'name' | 'amount' | 'type' | 'category'>,\n): BudgetItem {\n return {\n id: crypto.randomUUID\n ? crypto.randomUUID()\n : `${Date.now()}-${Math.random().toString(36).slice(2)}`,\n frequency: 'monthly',\n isEssential:\n overrides.type === 'expense'\n ? [\n 'housing',\n 'food',\n 'utilities',\n 'healthcare',\n 'insurance',\n 'transportation',\n 'debt',\n ].includes(overrides.category)\n : false,\n ...overrides,\n }\n}\nexport function get503020Breakdown(monthlyIncome: number): {\n needs: number\n wants: number\n savings: number\n} {\n return {\n needs: parseFloat((monthlyIncome * 0.5).toFixed(2)),\n wants: parseFloat((monthlyIncome * 0.3).toFixed(2)),\n savings: parseFloat((monthlyIncome * 0.2).toFixed(2)),\n }\n}\n"],"mappings":";;AAiGA,MAAa,qBAA8D;CACzE,SAAS;EAAE,KAAK;EAAW,OAAO;EAAW,MAA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ACN,GAAG;CACL;AACF;AACA,SAAgB,mBAAmB,eAIjC;CACA,OAAO;EACL,OAAO,YAAY,gBAAgB,GAAA,CAAK,QAAQ,CAAC,CAAC;EAClD,OAAO,YAAY,gBAAgB,GAAA,CAAK,QAAQ,CAAC,CAAC;EAClD,SAAS,YAAY,gBAAgB,GAAA,CAAK,QAAQ,CAAC,CAAC;CACtD;AACF"}
@@ -0,0 +1,4 @@
1
+ export type { BudgetAnalysis, BudgetCalculationError, BudgetCalculationResult, BudgetCategoryType, BudgetFrequency, BudgetHealthStatus, BudgetInput, BudgetItem, CategoryBreakdown, CategoryConfig, ExpenseCategory, IncomeCategory, } from './types';
2
+ export { EXPENSE_CATEGORIES, INCOME_CATEGORIES } from './types';
3
+ export { calculateBudget, createBudgetItem, get503020Breakdown, toAnnualAmount, toMonthlyAmount, validateBudgetInput, } from './calculator';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,cAAc,EACd,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC/D,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,mBAAmB,GACpB,MAAM,cAAc,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,317 @@
1
+ //#region src/types.ts
2
+ const EXPENSE_CATEGORIES = {
3
+ housing: {
4
+ key: "housing",
5
+ label: "Housing",
6
+ icon: "🏠",
7
+ suggestedPercent: 30
8
+ },
9
+ transportation: {
10
+ key: "transportation",
11
+ label: "Transportation",
12
+ icon: "🚗",
13
+ suggestedPercent: 10
14
+ },
15
+ food: {
16
+ key: "food",
17
+ label: "Food & Groceries",
18
+ icon: "🛒",
19
+ suggestedPercent: 12
20
+ },
21
+ utilities: {
22
+ key: "utilities",
23
+ label: "Utilities",
24
+ icon: "💡",
25
+ suggestedPercent: 5
26
+ },
27
+ healthcare: {
28
+ key: "healthcare",
29
+ label: "Healthcare",
30
+ icon: "🏥",
31
+ suggestedPercent: 5
32
+ },
33
+ insurance: {
34
+ key: "insurance",
35
+ label: "Insurance",
36
+ icon: "🛡️",
37
+ suggestedPercent: 5
38
+ },
39
+ savings: {
40
+ key: "savings",
41
+ label: "Savings & Investments",
42
+ icon: "💰",
43
+ suggestedPercent: 20
44
+ },
45
+ debt: {
46
+ key: "debt",
47
+ label: "Debt Payments",
48
+ icon: "💳",
49
+ suggestedPercent: 5
50
+ },
51
+ personal: {
52
+ key: "personal",
53
+ label: "Personal Care",
54
+ icon: "🧴"
55
+ },
56
+ entertainment: {
57
+ key: "entertainment",
58
+ label: "Entertainment",
59
+ icon: "🎬"
60
+ },
61
+ education: {
62
+ key: "education",
63
+ label: "Education",
64
+ icon: "📚"
65
+ },
66
+ clothing: {
67
+ key: "clothing",
68
+ label: "Clothing",
69
+ icon: "👕"
70
+ },
71
+ gifts: {
72
+ key: "gifts",
73
+ label: "Gifts & Donations",
74
+ icon: "🎁"
75
+ },
76
+ subscriptions: {
77
+ key: "subscriptions",
78
+ label: "Subscriptions",
79
+ icon: "📱"
80
+ },
81
+ other: {
82
+ key: "other",
83
+ label: "Other",
84
+ icon: "📦"
85
+ }
86
+ };
87
+ const INCOME_CATEGORIES = {
88
+ salary: {
89
+ key: "salary",
90
+ label: "Salary / Wages",
91
+ icon: "💼"
92
+ },
93
+ freelance: {
94
+ key: "freelance",
95
+ label: "Freelance / Contract",
96
+ icon: "💻"
97
+ },
98
+ investments: {
99
+ key: "investments",
100
+ label: "Investment Returns",
101
+ icon: "📈"
102
+ },
103
+ rental: {
104
+ key: "rental",
105
+ label: "Rental Income",
106
+ icon: "🏢"
107
+ },
108
+ business: {
109
+ key: "business",
110
+ label: "Business Income",
111
+ icon: "🏪"
112
+ },
113
+ pension: {
114
+ key: "pension",
115
+ label: "Pension",
116
+ icon: "🧓"
117
+ },
118
+ "social-benefits": {
119
+ key: "social-benefits",
120
+ label: "Social Benefits",
121
+ icon: "🏛️"
122
+ },
123
+ "gifts-received": {
124
+ key: "gifts-received",
125
+ label: "Gifts Received",
126
+ icon: "🎀"
127
+ },
128
+ other: {
129
+ key: "other",
130
+ label: "Other Income",
131
+ icon: "💵"
132
+ }
133
+ };
134
+ //#endregion
135
+ //#region src/calculator.ts
136
+ function toMonthlyAmount(amount, frequency) {
137
+ switch (frequency) {
138
+ case "weekly": return amount * (52 / 12);
139
+ case "biweekly": return amount * (26 / 12);
140
+ case "monthly": return amount;
141
+ case "quarterly": return amount / 3;
142
+ case "annually": return amount / 12;
143
+ case "one-time": return amount / 12;
144
+ default: return amount;
145
+ }
146
+ }
147
+ function toAnnualAmount(amount, frequency) {
148
+ switch (frequency) {
149
+ case "weekly": return amount * 52;
150
+ case "biweekly": return amount * 26;
151
+ case "monthly": return amount * 12;
152
+ case "quarterly": return amount * 4;
153
+ case "annually": return amount;
154
+ case "one-time": return amount;
155
+ default: return amount * 12;
156
+ }
157
+ }
158
+ function validateBudgetInput(input) {
159
+ if (!input.items || input.items.length === 0) return {
160
+ code: "NO_ITEMS",
161
+ message: "At least one budget item is required"
162
+ };
163
+ if (!input.items.some((item) => item.type === "income")) return {
164
+ code: "NO_INCOME",
165
+ message: "At least one income source is required"
166
+ };
167
+ for (const item of input.items) if (typeof item.amount !== "number" || isNaN(item.amount) || item.amount < 0) return {
168
+ code: "INVALID_AMOUNT",
169
+ message: `Invalid amount for "${item.name}": must be a non-negative number`,
170
+ field: item.id
171
+ };
172
+ return null;
173
+ }
174
+ function calculateBreakdowns(items, type, total) {
175
+ const categoryMap = /* @__PURE__ */ new Map();
176
+ for (const item of items) {
177
+ if (item.type !== type) continue;
178
+ const monthlyAmount = toMonthlyAmount(item.amount, item.frequency);
179
+ const existing = categoryMap.get(item.category) || {
180
+ amount: 0,
181
+ count: 0
182
+ };
183
+ categoryMap.set(item.category, {
184
+ amount: existing.amount + monthlyAmount,
185
+ count: existing.count + 1
186
+ });
187
+ }
188
+ return Array.from(categoryMap.entries()).map(([category, data]) => ({
189
+ category,
190
+ amount: parseFloat(data.amount.toFixed(2)),
191
+ percentage: total > 0 ? parseFloat((data.amount / total * 100).toFixed(1)) : 0,
192
+ itemCount: data.count
193
+ })).sort((a, b) => b.amount - a.amount);
194
+ }
195
+ function determineBudgetHealth(savingsRate, essentialRatio, monthlySurplus) {
196
+ let score = 50;
197
+ if (savingsRate >= 20) score += 30;
198
+ else if (savingsRate >= 15) score += 25;
199
+ else if (savingsRate >= 10) score += 15;
200
+ else if (savingsRate >= 5) score += 5;
201
+ else if (savingsRate < 0) score -= 20;
202
+ if (essentialRatio <= 50) score += 20;
203
+ else if (essentialRatio <= 60) score += 10;
204
+ else if (essentialRatio <= 70) score += 0;
205
+ else if (essentialRatio <= 80) score -= 10;
206
+ else score -= 20;
207
+ if (monthlySurplus > 0) score += 5;
208
+ else score -= 15;
209
+ score = Math.max(0, Math.min(100, score));
210
+ let status;
211
+ if (score >= 80) status = "excellent";
212
+ else if (score >= 65) status = "good";
213
+ else if (score >= 45) status = "fair";
214
+ else if (score >= 25) status = "poor";
215
+ else status = "critical";
216
+ return {
217
+ status,
218
+ score
219
+ };
220
+ }
221
+ function generateRecommendations(savingsRate, essentialRatio, monthlySurplus, _totalIncome, savingsGoalPercent, savingsGoalMet) {
222
+ const recommendations = [];
223
+ if (monthlySurplus < 0) recommendations.push("Your expenses exceed your income. Review discretionary spending for areas to cut back.");
224
+ if (savingsRate < 10) recommendations.push("Aim to save at least 10-20% of your income. Start small and gradually increase.");
225
+ if (essentialRatio > 70) recommendations.push("Essential expenses are consuming over 70% of your income. Look for ways to reduce fixed costs like housing or transportation.");
226
+ if (!savingsGoalMet && savingsGoalPercent > 0) recommendations.push(`You're not meeting your ${savingsGoalPercent}% savings goal. Consider reducing discretionary spending.`);
227
+ if (savingsRate >= 20 && essentialRatio <= 50) recommendations.push("Great financial health! Consider investing your surplus or building an emergency fund.");
228
+ if (monthlySurplus > 0 && savingsRate < 20) recommendations.push("You have a surplus — consider automating transfers to a savings or investment account.");
229
+ if (recommendations.length === 0) recommendations.push("Your budget looks balanced. Keep monitoring and adjusting as your financial situation changes.");
230
+ return recommendations;
231
+ }
232
+ function calculateBudget(input) {
233
+ const validationError = validateBudgetInput(input);
234
+ if (validationError) return {
235
+ success: false,
236
+ error: validationError
237
+ };
238
+ const { items, savingsGoalPercent = 20, emergencyFundMonths = 6 } = input;
239
+ let totalMonthlyIncome = 0;
240
+ let totalMonthlyExpenses = 0;
241
+ let essentialExpenses = 0;
242
+ let discretionaryExpenses = 0;
243
+ for (const item of items) {
244
+ const monthlyAmount = toMonthlyAmount(item.amount, item.frequency);
245
+ if (item.type === "income") totalMonthlyIncome += monthlyAmount;
246
+ else {
247
+ totalMonthlyExpenses += monthlyAmount;
248
+ if (item.isEssential) essentialExpenses += monthlyAmount;
249
+ else discretionaryExpenses += monthlyAmount;
250
+ }
251
+ }
252
+ const monthlySurplus = totalMonthlyIncome - totalMonthlyExpenses;
253
+ const annualIncome = totalMonthlyIncome * 12;
254
+ const annualExpenses = totalMonthlyExpenses * 12;
255
+ const annualSurplus = monthlySurplus * 12;
256
+ const savingsRate = totalMonthlyIncome > 0 ? monthlySurplus / totalMonthlyIncome * 100 : 0;
257
+ const targetSavingsAmount = totalMonthlyIncome * savingsGoalPercent / 100;
258
+ const savingsGoalMet = monthlySurplus >= targetSavingsAmount;
259
+ const essentialRatio = totalMonthlyIncome > 0 ? essentialExpenses / totalMonthlyIncome * 100 : 0;
260
+ const emergencyFundTarget = totalMonthlyExpenses * emergencyFundMonths;
261
+ const monthsToEmergencyFund = monthlySurplus > 0 ? Math.ceil(emergencyFundTarget / monthlySurplus) : null;
262
+ const expenseBreakdown = calculateBreakdowns(items, "expense", totalMonthlyExpenses);
263
+ const incomeBreakdown = calculateBreakdowns(items, "income", totalMonthlyIncome);
264
+ const { status: healthStatus, score: healthScore } = determineBudgetHealth(savingsRate, essentialRatio, monthlySurplus);
265
+ const recommendations = generateRecommendations(savingsRate, essentialRatio, monthlySurplus, totalMonthlyIncome, savingsGoalPercent, savingsGoalMet);
266
+ return {
267
+ success: true,
268
+ data: {
269
+ totalMonthlyIncome: parseFloat(totalMonthlyIncome.toFixed(2)),
270
+ totalMonthlyExpenses: parseFloat(totalMonthlyExpenses.toFixed(2)),
271
+ monthlySurplus: parseFloat(monthlySurplus.toFixed(2)),
272
+ annualIncome: parseFloat(annualIncome.toFixed(2)),
273
+ annualExpenses: parseFloat(annualExpenses.toFixed(2)),
274
+ annualSurplus: parseFloat(annualSurplus.toFixed(2)),
275
+ savingsRate: parseFloat(savingsRate.toFixed(1)),
276
+ savingsGoalMet,
277
+ targetSavingsAmount: parseFloat(targetSavingsAmount.toFixed(2)),
278
+ essentialExpenses: parseFloat(essentialExpenses.toFixed(2)),
279
+ discretionaryExpenses: parseFloat(discretionaryExpenses.toFixed(2)),
280
+ essentialRatio: parseFloat(essentialRatio.toFixed(1)),
281
+ expenseBreakdown,
282
+ incomeBreakdown,
283
+ healthStatus,
284
+ healthScore,
285
+ emergencyFundTarget: parseFloat(emergencyFundTarget.toFixed(2)),
286
+ monthsToEmergencyFund,
287
+ recommendations
288
+ }
289
+ };
290
+ }
291
+ function createBudgetItem(overrides) {
292
+ return {
293
+ id: crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`,
294
+ frequency: "monthly",
295
+ isEssential: overrides.type === "expense" ? [
296
+ "housing",
297
+ "food",
298
+ "utilities",
299
+ "healthcare",
300
+ "insurance",
301
+ "transportation",
302
+ "debt"
303
+ ].includes(overrides.category) : false,
304
+ ...overrides
305
+ };
306
+ }
307
+ function get503020Breakdown(monthlyIncome) {
308
+ return {
309
+ needs: parseFloat((monthlyIncome * .5).toFixed(2)),
310
+ wants: parseFloat((monthlyIncome * .3).toFixed(2)),
311
+ savings: parseFloat((monthlyIncome * .2).toFixed(2))
312
+ };
313
+ }
314
+ //#endregion
315
+ export { EXPENSE_CATEGORIES, INCOME_CATEGORIES, calculateBudget, createBudgetItem, get503020Breakdown, toAnnualAmount, toMonthlyAmount, validateBudgetInput };
316
+
317
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/types.ts","../src/calculator.ts"],"sourcesContent":["export type BudgetCategoryType = 'income' | 'expense'\nexport type ExpenseCategory =\n | 'housing'\n | 'transportation'\n | 'food'\n | 'utilities'\n | 'healthcare'\n | 'insurance'\n | 'savings'\n | 'debt'\n | 'personal'\n | 'entertainment'\n | 'education'\n | 'clothing'\n | 'gifts'\n | 'subscriptions'\n | 'other'\nexport type IncomeCategory =\n | 'salary'\n | 'freelance'\n | 'investments'\n | 'rental'\n | 'business'\n | 'pension'\n | 'social-benefits'\n | 'gifts-received'\n | 'other'\nexport type BudgetFrequency =\n | 'monthly'\n | 'weekly'\n | 'biweekly'\n | 'quarterly'\n | 'annually'\n | 'one-time'\nexport interface BudgetItem {\n id: string\n name: string\n amount: number\n type: BudgetCategoryType\n category: ExpenseCategory | IncomeCategory\n frequency: BudgetFrequency\n isEssential: boolean\n}\nexport interface BudgetInput {\n items: BudgetItem[]\n currency?: string\n savingsGoalPercent?: number\n emergencyFundMonths?: number\n}\nexport interface CategoryBreakdown {\n category: string\n amount: number\n percentage: number\n itemCount: number\n}\nexport type BudgetHealthStatus = 'excellent' | 'good' | 'fair' | 'poor' | 'critical'\nexport interface BudgetAnalysis {\n totalMonthlyIncome: number\n totalMonthlyExpenses: number\n monthlySurplus: number\n annualIncome: number\n annualExpenses: number\n annualSurplus: number\n savingsRate: number\n savingsGoalMet: boolean\n targetSavingsAmount: number\n essentialExpenses: number\n discretionaryExpenses: number\n essentialRatio: number\n expenseBreakdown: CategoryBreakdown[]\n incomeBreakdown: CategoryBreakdown[]\n healthStatus: BudgetHealthStatus\n healthScore: number\n emergencyFundTarget: number\n monthsToEmergencyFund: number | null\n recommendations: string[]\n}\nexport interface BudgetCalculationError {\n code: 'NO_ITEMS' | 'NO_INCOME' | 'INVALID_AMOUNT' | 'INVALID_INPUT'\n message: string\n field?: string\n}\nexport type BudgetCalculationResult =\n | {\n success: true\n data: BudgetAnalysis\n }\n | {\n success: false\n error: BudgetCalculationError\n }\nexport interface CategoryConfig {\n key: string\n label: string\n icon: string\n suggestedPercent?: number\n}\nexport const EXPENSE_CATEGORIES: Record<ExpenseCategory, CategoryConfig> = {\n housing: { key: 'housing', label: 'Housing', icon: '🏠', suggestedPercent: 30 },\n transportation: {\n key: 'transportation',\n label: 'Transportation',\n icon: '🚗',\n suggestedPercent: 10,\n },\n food: { key: 'food', label: 'Food & Groceries', icon: '🛒', suggestedPercent: 12 },\n utilities: { key: 'utilities', label: 'Utilities', icon: '💡', suggestedPercent: 5 },\n healthcare: { key: 'healthcare', label: 'Healthcare', icon: '🏥', suggestedPercent: 5 },\n insurance: { key: 'insurance', label: 'Insurance', icon: '🛡️', suggestedPercent: 5 },\n savings: { key: 'savings', label: 'Savings & Investments', icon: '💰', suggestedPercent: 20 },\n debt: { key: 'debt', label: 'Debt Payments', icon: '💳', suggestedPercent: 5 },\n personal: { key: 'personal', label: 'Personal Care', icon: '🧴' },\n entertainment: { key: 'entertainment', label: 'Entertainment', icon: '🎬' },\n education: { key: 'education', label: 'Education', icon: '📚' },\n clothing: { key: 'clothing', label: 'Clothing', icon: '👕' },\n gifts: { key: 'gifts', label: 'Gifts & Donations', icon: '🎁' },\n subscriptions: { key: 'subscriptions', label: 'Subscriptions', icon: '📱' },\n other: { key: 'other', label: 'Other', icon: '📦' },\n}\nexport const INCOME_CATEGORIES: Record<IncomeCategory, CategoryConfig> = {\n salary: { key: 'salary', label: 'Salary / Wages', icon: '💼' },\n freelance: { key: 'freelance', label: 'Freelance / Contract', icon: '💻' },\n investments: { key: 'investments', label: 'Investment Returns', icon: '📈' },\n rental: { key: 'rental', label: 'Rental Income', icon: '🏢' },\n business: { key: 'business', label: 'Business Income', icon: '🏪' },\n pension: { key: 'pension', label: 'Pension', icon: '🧓' },\n 'social-benefits': { key: 'social-benefits', label: 'Social Benefits', icon: '🏛️' },\n 'gifts-received': { key: 'gifts-received', label: 'Gifts Received', icon: '🎀' },\n other: { key: 'other', label: 'Other Income', icon: '💵' },\n}\n","import type {\n BudgetAnalysis,\n BudgetCalculationError,\n BudgetCalculationResult,\n BudgetFrequency,\n BudgetHealthStatus,\n BudgetInput,\n BudgetItem,\n CategoryBreakdown,\n} from './types'\nexport function toMonthlyAmount(amount: number, frequency: BudgetFrequency): number {\n switch (frequency) {\n case 'weekly':\n return amount * (52 / 12)\n case 'biweekly':\n return amount * (26 / 12)\n case 'monthly':\n return amount\n case 'quarterly':\n return amount / 3\n case 'annually':\n return amount / 12\n case 'one-time':\n return amount / 12\n default:\n return amount\n }\n}\nexport function toAnnualAmount(amount: number, frequency: BudgetFrequency): number {\n switch (frequency) {\n case 'weekly':\n return amount * 52\n case 'biweekly':\n return amount * 26\n case 'monthly':\n return amount * 12\n case 'quarterly':\n return amount * 4\n case 'annually':\n return amount\n case 'one-time':\n return amount\n default:\n return amount * 12\n }\n}\nexport function validateBudgetInput(input: BudgetInput): BudgetCalculationError | null {\n if (!input.items || input.items.length === 0) {\n return {\n code: 'NO_ITEMS',\n message: 'At least one budget item is required',\n }\n }\n const hasIncome = input.items.some((item) => item.type === 'income')\n if (!hasIncome) {\n return {\n code: 'NO_INCOME',\n message: 'At least one income source is required',\n }\n }\n for (const item of input.items) {\n if (typeof item.amount !== 'number' || isNaN(item.amount) || item.amount < 0) {\n return {\n code: 'INVALID_AMOUNT',\n message: `Invalid amount for \"${item.name}\": must be a non-negative number`,\n field: item.id,\n }\n }\n }\n return null\n}\nfunction calculateBreakdowns(\n items: BudgetItem[],\n type: 'income' | 'expense',\n total: number,\n): CategoryBreakdown[] {\n const categoryMap = new Map<\n string,\n {\n amount: number\n count: number\n }\n >()\n for (const item of items) {\n if (item.type !== type) continue\n const monthlyAmount = toMonthlyAmount(item.amount, item.frequency)\n const existing = categoryMap.get(item.category) || { amount: 0, count: 0 }\n categoryMap.set(item.category, {\n amount: existing.amount + monthlyAmount,\n count: existing.count + 1,\n })\n }\n return Array.from(categoryMap.entries())\n .map(([category, data]) => ({\n category,\n amount: parseFloat(data.amount.toFixed(2)),\n percentage: total > 0 ? parseFloat(((data.amount / total) * 100).toFixed(1)) : 0,\n itemCount: data.count,\n }))\n .sort((a, b) => b.amount - a.amount)\n}\nfunction determineBudgetHealth(\n savingsRate: number,\n essentialRatio: number,\n monthlySurplus: number,\n): {\n status: BudgetHealthStatus\n score: number\n} {\n let score = 50\n if (savingsRate >= 20) score += 30\n else if (savingsRate >= 15) score += 25\n else if (savingsRate >= 10) score += 15\n else if (savingsRate >= 5) score += 5\n else if (savingsRate < 0) score -= 20\n if (essentialRatio <= 50) score += 20\n else if (essentialRatio <= 60) score += 10\n else if (essentialRatio <= 70) score += 0\n else if (essentialRatio <= 80) score -= 10\n else score -= 20\n if (monthlySurplus > 0) score += 5\n else score -= 15\n score = Math.max(0, Math.min(100, score))\n let status: BudgetHealthStatus\n if (score >= 80) status = 'excellent'\n else if (score >= 65) status = 'good'\n else if (score >= 45) status = 'fair'\n else if (score >= 25) status = 'poor'\n else status = 'critical'\n return { status, score }\n}\nfunction generateRecommendations(\n savingsRate: number,\n essentialRatio: number,\n monthlySurplus: number,\n _totalIncome: number,\n savingsGoalPercent: number,\n savingsGoalMet: boolean,\n): string[] {\n const recommendations: string[] = []\n if (monthlySurplus < 0) {\n recommendations.push(\n 'Your expenses exceed your income. Review discretionary spending for areas to cut back.',\n )\n }\n if (savingsRate < 10) {\n recommendations.push(\n 'Aim to save at least 10-20% of your income. Start small and gradually increase.',\n )\n }\n if (essentialRatio > 70) {\n recommendations.push(\n 'Essential expenses are consuming over 70% of your income. Look for ways to reduce fixed costs like housing or transportation.',\n )\n }\n if (!savingsGoalMet && savingsGoalPercent > 0) {\n recommendations.push(\n `You're not meeting your ${savingsGoalPercent}% savings goal. Consider reducing discretionary spending.`,\n )\n }\n if (savingsRate >= 20 && essentialRatio <= 50) {\n recommendations.push(\n 'Great financial health! Consider investing your surplus or building an emergency fund.',\n )\n }\n if (monthlySurplus > 0 && savingsRate < 20) {\n recommendations.push(\n 'You have a surplus — consider automating transfers to a savings or investment account.',\n )\n }\n if (recommendations.length === 0) {\n recommendations.push(\n 'Your budget looks balanced. Keep monitoring and adjusting as your financial situation changes.',\n )\n }\n return recommendations\n}\nexport function calculateBudget(input: BudgetInput): BudgetCalculationResult {\n const validationError = validateBudgetInput(input)\n if (validationError) {\n return { success: false, error: validationError }\n }\n const { items, savingsGoalPercent = 20, emergencyFundMonths = 6 } = input\n let totalMonthlyIncome = 0\n let totalMonthlyExpenses = 0\n let essentialExpenses = 0\n let discretionaryExpenses = 0\n for (const item of items) {\n const monthlyAmount = toMonthlyAmount(item.amount, item.frequency)\n if (item.type === 'income') {\n totalMonthlyIncome += monthlyAmount\n } else {\n totalMonthlyExpenses += monthlyAmount\n if (item.isEssential) {\n essentialExpenses += monthlyAmount\n } else {\n discretionaryExpenses += monthlyAmount\n }\n }\n }\n const monthlySurplus = totalMonthlyIncome - totalMonthlyExpenses\n const annualIncome = totalMonthlyIncome * 12\n const annualExpenses = totalMonthlyExpenses * 12\n const annualSurplus = monthlySurplus * 12\n const savingsRate = totalMonthlyIncome > 0 ? (monthlySurplus / totalMonthlyIncome) * 100 : 0\n const targetSavingsAmount = (totalMonthlyIncome * savingsGoalPercent) / 100\n const savingsGoalMet = monthlySurplus >= targetSavingsAmount\n const essentialRatio = totalMonthlyIncome > 0 ? (essentialExpenses / totalMonthlyIncome) * 100 : 0\n const emergencyFundTarget = totalMonthlyExpenses * emergencyFundMonths\n const monthsToEmergencyFund =\n monthlySurplus > 0 ? Math.ceil(emergencyFundTarget / monthlySurplus) : null\n const expenseBreakdown = calculateBreakdowns(items, 'expense', totalMonthlyExpenses)\n const incomeBreakdown = calculateBreakdowns(items, 'income', totalMonthlyIncome)\n const { status: healthStatus, score: healthScore } = determineBudgetHealth(\n savingsRate,\n essentialRatio,\n monthlySurplus,\n )\n const recommendations = generateRecommendations(\n savingsRate,\n essentialRatio,\n monthlySurplus,\n totalMonthlyIncome,\n savingsGoalPercent,\n savingsGoalMet,\n )\n const analysis: BudgetAnalysis = {\n totalMonthlyIncome: parseFloat(totalMonthlyIncome.toFixed(2)),\n totalMonthlyExpenses: parseFloat(totalMonthlyExpenses.toFixed(2)),\n monthlySurplus: parseFloat(monthlySurplus.toFixed(2)),\n annualIncome: parseFloat(annualIncome.toFixed(2)),\n annualExpenses: parseFloat(annualExpenses.toFixed(2)),\n annualSurplus: parseFloat(annualSurplus.toFixed(2)),\n savingsRate: parseFloat(savingsRate.toFixed(1)),\n savingsGoalMet,\n targetSavingsAmount: parseFloat(targetSavingsAmount.toFixed(2)),\n essentialExpenses: parseFloat(essentialExpenses.toFixed(2)),\n discretionaryExpenses: parseFloat(discretionaryExpenses.toFixed(2)),\n essentialRatio: parseFloat(essentialRatio.toFixed(1)),\n expenseBreakdown,\n incomeBreakdown,\n healthStatus,\n healthScore,\n emergencyFundTarget: parseFloat(emergencyFundTarget.toFixed(2)),\n monthsToEmergencyFund,\n recommendations,\n }\n return { success: true, data: analysis }\n}\nexport function createBudgetItem(\n overrides: Partial<BudgetItem> & Pick<BudgetItem, 'name' | 'amount' | 'type' | 'category'>,\n): BudgetItem {\n return {\n id: crypto.randomUUID\n ? crypto.randomUUID()\n : `${Date.now()}-${Math.random().toString(36).slice(2)}`,\n frequency: 'monthly',\n isEssential:\n overrides.type === 'expense'\n ? [\n 'housing',\n 'food',\n 'utilities',\n 'healthcare',\n 'insurance',\n 'transportation',\n 'debt',\n ].includes(overrides.category)\n : false,\n ...overrides,\n }\n}\nexport function get503020Breakdown(monthlyIncome: number): {\n needs: number\n wants: number\n savings: number\n} {\n return {\n needs: parseFloat((monthlyIncome * 0.5).toFixed(2)),\n wants: parseFloat((monthlyIncome * 0.3).toFixed(2)),\n savings: parseFloat((monthlyIncome * 0.2).toFixed(2)),\n }\n}\n"],"mappings":";AAiGA,MAAa,qBAA8D;CACzE,SAAS;EAAE,KAAK;EAAW,OAAO;EAAW,MAAM;EAAM,kBAAkB;CAAG;CAC9E,gBAAgB;EACd,KAAK;EACL,OAAO;EACP,MAAM;EACN,kBAAkB;CACpB;CACA,MAAM;EAAE,KAAK;EAAQ,OAAO;EAAoB,MAAM;EAAM,kBAAkB;CAAG;CACjF,WAAW;EAAE,KAAK;EAAa,OAAO;EAAa,MAAM;EAAM,kBAAkB;CAAE;CACnF,YAAY;EAAE,KAAK;EAAc,OAAO;EAAc,MAAM;EAAM,kBAAkB;CAAE;CACtF,WAAW;EAAE,KAAK;EAAa,OAAO;EAAa,MAAM;EAAO,kBAAkB;CAAE;CACpF,SAAS;EAAE,KAAK;EAAW,OAAO;EAAyB,MAAM;EAAM,kBAAkB;CAAG;CAC5F,MAAM;EAAE,KAAK;EAAQ,OAAO;EAAiB,MAAM;EAAM,kBAAkB;CAAE;CAC7E,UAAU;EAAE,KAAK;EAAY,OAAO;EAAiB,MAAM;CAAK;CAChE,eAAe;EAAE,KAAK;EAAiB,OAAO;EAAiB,MAAM;CAAK;CAC1E,WAAW;EAAE,KAAK;EAAa,OAAO;EAAa,MAAM;CAAK;CAC9D,UAAU;EAAE,KAAK;EAAY,OAAO;EAAY,MAAM;CAAK;CAC3D,OAAO;EAAE,KAAK;EAAS,OAAO;EAAqB,MAAM;CAAK;CAC9D,eAAe;EAAE,KAAK;EAAiB,OAAO;EAAiB,MAAM;CAAK;CAC1E,OAAO;EAAE,KAAK;EAAS,OAAO;EAAS,MAAM;CAAK;AACpD;AACA,MAAa,oBAA4D;CACvE,QAAQ;EAAE,KAAK;EAAU,OAAO;EAAkB,MAAM;CAAK;CAC7D,WA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AI,OAAO,aACP,OAAO,WAAW,IAClB,GAAG,KAAK,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC;EACvD,WAAW;EACX,aACE,UAAU,SAAS,YACf;GACE;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAAC,CAAC,SAAS,UAAU,QAAQ,IAC7B;EACN,GAAG;CACL;AACF;AACA,SAAgB,mBAAmB,eAIjC;CACA,OAAO;EACL,OAAO,YAAY,gBAAgB,GAAA,CAAK,QAAQ,CAAC,CAAC;EAClD,OAAO,YAAY,gBAAgB,GAAA,CAAK,QAAQ,CAAC,CAAC;EAClD,SAAS,YAAY,gBAAgB,GAAA,CAAK,QAAQ,CAAC,CAAC;CACtD;AACF"}
@@ -0,0 +1,68 @@
1
+ export type BudgetCategoryType = 'income' | 'expense';
2
+ export type ExpenseCategory = 'housing' | 'transportation' | 'food' | 'utilities' | 'healthcare' | 'insurance' | 'savings' | 'debt' | 'personal' | 'entertainment' | 'education' | 'clothing' | 'gifts' | 'subscriptions' | 'other';
3
+ export type IncomeCategory = 'salary' | 'freelance' | 'investments' | 'rental' | 'business' | 'pension' | 'social-benefits' | 'gifts-received' | 'other';
4
+ export type BudgetFrequency = 'monthly' | 'weekly' | 'biweekly' | 'quarterly' | 'annually' | 'one-time';
5
+ export interface BudgetItem {
6
+ id: string;
7
+ name: string;
8
+ amount: number;
9
+ type: BudgetCategoryType;
10
+ category: ExpenseCategory | IncomeCategory;
11
+ frequency: BudgetFrequency;
12
+ isEssential: boolean;
13
+ }
14
+ export interface BudgetInput {
15
+ items: BudgetItem[];
16
+ currency?: string;
17
+ savingsGoalPercent?: number;
18
+ emergencyFundMonths?: number;
19
+ }
20
+ export interface CategoryBreakdown {
21
+ category: string;
22
+ amount: number;
23
+ percentage: number;
24
+ itemCount: number;
25
+ }
26
+ export type BudgetHealthStatus = 'excellent' | 'good' | 'fair' | 'poor' | 'critical';
27
+ export interface BudgetAnalysis {
28
+ totalMonthlyIncome: number;
29
+ totalMonthlyExpenses: number;
30
+ monthlySurplus: number;
31
+ annualIncome: number;
32
+ annualExpenses: number;
33
+ annualSurplus: number;
34
+ savingsRate: number;
35
+ savingsGoalMet: boolean;
36
+ targetSavingsAmount: number;
37
+ essentialExpenses: number;
38
+ discretionaryExpenses: number;
39
+ essentialRatio: number;
40
+ expenseBreakdown: CategoryBreakdown[];
41
+ incomeBreakdown: CategoryBreakdown[];
42
+ healthStatus: BudgetHealthStatus;
43
+ healthScore: number;
44
+ emergencyFundTarget: number;
45
+ monthsToEmergencyFund: number | null;
46
+ recommendations: string[];
47
+ }
48
+ export interface BudgetCalculationError {
49
+ code: 'NO_ITEMS' | 'NO_INCOME' | 'INVALID_AMOUNT' | 'INVALID_INPUT';
50
+ message: string;
51
+ field?: string;
52
+ }
53
+ export type BudgetCalculationResult = {
54
+ success: true;
55
+ data: BudgetAnalysis;
56
+ } | {
57
+ success: false;
58
+ error: BudgetCalculationError;
59
+ };
60
+ export interface CategoryConfig {
61
+ key: string;
62
+ label: string;
63
+ icon: string;
64
+ suggestedPercent?: number;
65
+ }
66
+ export declare const EXPENSE_CATEGORIES: Record<ExpenseCategory, CategoryConfig>;
67
+ export declare const INCOME_CATEGORIES: Record<IncomeCategory, CategoryConfig>;
68
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,SAAS,CAAA;AACrD,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,gBAAgB,GAChB,MAAM,GACN,WAAW,GACX,YAAY,GACZ,WAAW,GACX,SAAS,GACT,MAAM,GACN,UAAU,GACV,eAAe,GACf,WAAW,GACX,UAAU,GACV,OAAO,GACP,eAAe,GACf,OAAO,CAAA;AACX,MAAM,MAAM,cAAc,GACtB,QAAQ,GACR,WAAW,GACX,aAAa,GACb,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AAc,EAAE,MAAM,CAAA;IACtB,gBAAgB,EAAE,iBAAiB,EAAE,CAAA;IACrC,eAAe,EAAE,iBAAiB,EAAE,CAAA;IACpC,YAAY,EAAE,kBAAkB,CAAA;IAChC,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAA;IACpC,eAAe,EAAE,MAAM,EAAE,CAAA;CAC1B;AACD,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,UAAU,GAAG,WAAW,GAAG,gBAAgB,GAAG,eAAe,CAAA;IACnE,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AACD,MAAM,MAAM,uBAAuB,GAC/B;IACE,OAAO,EAAE,IAAI,CAAA;IACb,IAAI,EAAE,cAAc,CAAA;CACrB,GACD;IACE,OAAO,EAAE,KAAK,CAAA;IACd,KAAK,EAAE,sBAAsB,CAAA;CAC9B,CAAA;AACL,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AACD,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,eAAe,EAAE,cAAc,CAqBtE,CAAA;AACD,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,cAAc,EAAE,cAAc,CAUpE,CAAA"}
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@helpu/headless-budget-calculator",
3
+ "version": "1.0.0",
4
+ "description": "A headless, framework-agnostic budget calculator with income/expense categorization, savings goals, and budget analysis",
5
+ "keywords": [
6
+ "budget",
7
+ "calculator",
8
+ "finance",
9
+ "budgeting",
10
+ "savings",
11
+ "income",
12
+ "expenses",
13
+ "headless"
14
+ ],
15
+ "author": "HelpU Finance",
16
+ "license": "PolyForm-Noncommercial-1.0.0",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/helpufinance/headless-budget-calculator.git"
20
+ },
21
+ "homepage": "https://github.com/helpufinance/headless-budget-calculator#readme",
22
+ "bugs": {
23
+ "url": "https://github.com/helpufinance/headless-budget-calculator/issues"
24
+ },
25
+ "type": "module",
26
+ "main": "./dist/index.cjs",
27
+ "module": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "import": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/index.d.cts",
37
+ "default": "./dist/index.cjs"
38
+ }
39
+ }
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "README.md",
44
+ "LICENSE",
45
+ "COMMERCIAL-LICENSING.md"
46
+ ],
47
+ "sideEffects": false,
48
+ "engines": {
49
+ "node": ">=18.0.0"
50
+ },
51
+ "scripts": {
52
+ "build": "rolldown -c rolldown.config.ts && tsc --emitDeclarationOnly --declaration --outDir dist",
53
+ "dev": "rolldown -c rolldown.config.ts --watch",
54
+ "typecheck": "tsc --noEmit",
55
+ "test": "vitest run",
56
+ "test:coverage": "vitest run --coverage",
57
+ "test:watch": "vitest",
58
+ "lint": "oxlint src/*.ts tests/*.ts",
59
+ "lint:fix": "oxlint --fix src/*.ts tests/*.ts",
60
+ "format": "oxfmt src/*.ts tests/*.ts rolldown.config.ts vitest.config.ts",
61
+ "format:check": "oxfmt --check src/*.ts tests/*.ts rolldown.config.ts vitest.config.ts",
62
+ "clean": "rm -rf dist",
63
+ "prepublishOnly": "npm run clean && npm run build"
64
+ },
65
+ "devDependencies": {
66
+ "@types/node": "^26.4.1",
67
+ "@vitest/coverage-v8": "^5.0.0",
68
+ "oxfmt": "^0.67.0",
69
+ "oxlint": "^1.82.0",
70
+ "rolldown": "^1.2.8",
71
+ "typescript": "^7.0.2",
72
+ "vitest": "^5.0.0"
73
+ }
74
+ }