@helpu/headless-loan-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,290 @@
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 Loan Calculator
8
+
9
+ A headless, framework-agnostic loan calculator with support for VAT, multiple currencies, and full amortization schedules. Zero dependencies, works in Node.js, Bun, and browsers.
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
+ ## Features
18
+
19
+ - **Full amortization schedule** - Get detailed month-by-month payment breakdown
20
+ - **VAT support** - Calculate with net or gross prices, with configurable VAT rates
21
+ - **Multi-currency** - Support for 35+ currencies with proper formatting
22
+ - **Open & Closed loans** - Support for both traditional loans and balloon payment structures
23
+ - **Zero dependencies** - Lightweight and fast
24
+ - **TypeScript first** - Full type safety and IntelliSense support
25
+ - **Universal** - Works with Node.js, Bun, and in browsers
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ # npm
31
+ npm install @helpu/headless-loan-calculator
32
+
33
+ # yarn
34
+ yarn add @helpu/headless-loan-calculator
35
+
36
+ # pnpm
37
+ pnpm add @helpu/headless-loan-calculator
38
+
39
+ # bun
40
+ bun add @helpu/headless-loan-calculator
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ ```typescript
46
+ import { calculateLoan, formatCurrency } from '@helpu/headless-loan-calculator'
47
+
48
+ const result = calculateLoan({
49
+ price: 25000, // Total price
50
+ loanTermMonths: 60, // 5 years
51
+ apr: 6.5, // 6.5% APR
52
+ initialPayment: 5000, // $5,000 down payment
53
+ residualValue: 0, // No balloon payment
54
+ loanType: 'closed', // Standard loan
55
+ priceMode: 'gross', // Price includes VAT
56
+ vatRate: 0.21, // 21% VAT
57
+ })
58
+
59
+ if (result.success) {
60
+ console.log('Monthly payment:', formatCurrency('USD', result.data.monthlyPayment))
61
+ console.log('Total interest:', formatCurrency('USD', result.data.totalInterestAmount))
62
+ console.log('Total repayment:', formatCurrency('USD', result.data.totalRepayment))
63
+ }
64
+ ```
65
+
66
+ ## API Reference
67
+
68
+ ### `calculateLoan(input)`
69
+
70
+ Calculate a complete loan with amortization schedule.
71
+
72
+ ```typescript
73
+ interface LoanCalculationInput {
74
+ price: number
75
+ loanTermMonths: number
76
+ apr: number
77
+ initialPayment?: number
78
+ residualValue?: number
79
+ loanType: 'closed' | 'open'
80
+ priceMode: 'gross' | 'net'
81
+ vatRate: number
82
+ }
83
+ ```
84
+
85
+ Returns a result object:
86
+
87
+ ```typescript
88
+ interface LoanCalculationResult {
89
+ totalFinancedAmount: number
90
+ totalInterestAmount: number
91
+ totalVatAmount: number
92
+ totalRepayment: number
93
+ monthlyPayment: number
94
+ paymentSchedule: MonthlyPayment[]
95
+ input: LoanCalculationInput
96
+ }
97
+ ```
98
+
99
+ ### `calculateMonthlyPayment(principal, monthlyRate, termMonths)`
100
+
101
+ Calculate the monthly payment for a loan using the amortization formula.
102
+
103
+ ```typescript
104
+ import { calculateMonthlyPayment } from '@helpu/headless-loan-calculator'
105
+
106
+ const monthlyPayment = calculateMonthlyPayment(
107
+ 20000, // Principal
108
+ 0.005, // Monthly rate (6% APR / 12)
109
+ 60 // Term in months
110
+ )
111
+ ```
112
+
113
+ ### `calculateAffordableLoan(monthlyPayment, monthlyRate, termMonths)`
114
+
115
+ Calculate how much you can borrow based on a desired monthly payment.
116
+
117
+ ```typescript
118
+ import { calculateAffordableLoan } from '@helpu/headless-loan-calculator'
119
+
120
+ const maxLoan = calculateAffordableLoan(
121
+ 500, // Desired monthly payment
122
+ 0.005, // Monthly rate
123
+ 60 // Term in months
124
+ )
125
+ ```
126
+
127
+ ### `formatCurrency(currency, amount)`
128
+
129
+ Format a number as currency with proper locale-specific formatting.
130
+
131
+ ```typescript
132
+ import { formatCurrency } from '@helpu/headless-loan-calculator'
133
+
134
+ formatCurrency('EUR', 1234.56) // "1 234,56 €"
135
+ formatCurrency('USD', 1234.56) // "$1,234.56"
136
+ formatCurrency('HUF', 123456) // "123 456 Ft"
137
+ ```
138
+
139
+ ### `getVatRate(vatRateKey, customRate?)`
140
+
141
+ Get the VAT rate for a specific region.
142
+
143
+ ```typescript
144
+ import { getVatRate } from '@helpu/headless-loan-calculator'
145
+
146
+ getVatRate('EU') // 0.21 (21%)
147
+ getVatRate('DE') // 0.19 (19%)
148
+ getVatRate('Custom', 15) // 0.15 (15%)
149
+ ```
150
+
151
+ ## Loan Types
152
+
153
+ ### Closed Loan (Standard)
154
+
155
+ Traditional loan where the full amount is financed and paid off over the term.
156
+
157
+ ```typescript
158
+ const result = calculateLoan({
159
+ price: 30000,
160
+ loanTermMonths: 48,
161
+ apr: 5.9,
162
+ loanType: 'closed',
163
+ priceMode: 'gross',
164
+ vatRate: 0.21,
165
+ })
166
+ ```
167
+
168
+ ### Open Loan (Balloon Payment)
169
+
170
+ Loan with a residual value that is paid as a lump sum at the end.
171
+
172
+ ```typescript
173
+ const result = calculateLoan({
174
+ price: 30000,
175
+ loanTermMonths: 48,
176
+ apr: 5.9,
177
+ residualValue: 10000, // Balloon payment at end
178
+ loanType: 'open',
179
+ priceMode: 'gross',
180
+ vatRate: 0.21,
181
+ })
182
+ ```
183
+
184
+ ## Price Modes
185
+
186
+ ### Gross Mode (Default)
187
+
188
+ Use when the price includes VAT. Common for consumer/retail scenarios.
189
+
190
+ ```typescript
191
+ const result = calculateLoan({
192
+ price: 12100,
193
+ priceMode: 'gross',
194
+ vatRate: 0.21,
195
+ ...
196
+ })
197
+ ```
198
+
199
+ ### Net Mode
200
+
201
+ Use when the price excludes VAT. Common for B2B scenarios where VAT can be deducted.
202
+
203
+ ```typescript
204
+ const result = calculateLoan({
205
+ price: 10000,
206
+ priceMode: 'net',
207
+ vatRate: 0.21,
208
+ ...
209
+ })
210
+ ```
211
+
212
+ ## Supported Currencies
213
+
214
+ The library supports 35+ currencies across all regions:
215
+
216
+ - **Europe**: EUR, GBP, CHF, SEK, NOK, DKK, PLN, CZK, RON, HUF
217
+ - **Americas**: USD, CAD, MXN, BRL, ARS, CLP, COP, PEN
218
+ - **Asia**: JPY, CNY, HKD, KRW, SGD, INR, THB, MYR, IDR, PHP
219
+ - **Middle East & Africa**: AED, SAR, ILS, ZAR
220
+ - **Oceania**: AUD, NZD
221
+ - **Other**: RUB, TRY
222
+
223
+ ## Error Handling
224
+
225
+ The library uses a Result type pattern for safe error handling:
226
+
227
+ ```typescript
228
+ const result = calculateLoan(input)
229
+
230
+ if (result.success) {
231
+ console.log(result.data.monthlyPayment)
232
+ } else {
233
+ console.error(result.error.code, result.error.message)
234
+ }
235
+ ```
236
+
237
+ Possible error codes:
238
+
239
+ - `INVALID_PRICE` - Price must be a positive number
240
+ - `INVALID_TERM` - Loan term must be a positive integer
241
+ - `INVALID_APR` - APR must be a non-negative number
242
+ - `INITIAL_PAYMENT_TOO_HIGH` - Initial payment exceeds price
243
+ - `RESIDUAL_VALUE_TOO_HIGH` - Residual value exceeds financed amount
244
+
245
+ ## TypeScript Support
246
+
247
+ Full TypeScript support with exported types:
248
+
249
+ ```typescript
250
+ import type {
251
+ LoanCalculationInput,
252
+ LoanCalculationResult,
253
+ MonthlyPayment,
254
+ Currency,
255
+ LoanType,
256
+ PriceMode,
257
+ } from '@helpu/headless-loan-calculator'
258
+ ```
259
+
260
+ ## Testing
261
+
262
+ Install the repository dependencies and run the test suite with:
263
+
264
+ ```bash
265
+ npm test
266
+ ```
267
+
268
+ ## Contributing
269
+
270
+ Contributions are welcome. Please read the [contribution guidelines](https://docs.omisai.com/contribution-guidelines) before opening a pull request.
271
+
272
+ ## Sponsor
273
+
274
+ Support HelpU Finance through [GitHub Sponsors](https://github.com/sponsors/helpufinance).
275
+
276
+ ## License
277
+
278
+ This project is available for permitted non-commercial use under the **PolyForm Noncommercial License 1.0.0**.
279
+
280
+ Personal learning, education, research, experimentation, and other uses permitted by the PolyForm Noncommercial License are welcome.
281
+
282
+ **Commercial use requires a separate license from Omisai Technologies.**
283
+
284
+ Commercial licensing helps fund the HelpU Finance mission of creating freely accessible financial tools, educational resources, and technology.
285
+
286
+ For commercial licensing, see [`COMMERCIAL-LICENSING.md`](./COMMERCIAL-LICENSING.md).
287
+
288
+ Copyright (c) 2026 Omisai Technologies.
289
+
290
+ HelpU Finance is a project and brand of Omisai Technologies.
@@ -0,0 +1,8 @@
1
+ import type { LoanCalculationError, LoanCalculationInput, LoanCalculationResultOrError } from './types';
2
+ export declare function validateInput(input: LoanCalculationInput): LoanCalculationError | null;
3
+ export declare function calculateMonthlyPayment(principal: number, monthlyRate: number, termMonths: number): number;
4
+ export declare function calculateLoan(input: LoanCalculationInput): LoanCalculationResultOrError;
5
+ export declare function calculateAffordableLoan(monthlyPayment: number, monthlyRate: number, termMonths: number): number;
6
+ export declare function calculateTotalInterest(principal: number, monthlyPayment: number, termMonths: number): number;
7
+ export declare function getVatRate(vatRateKey: string, customRate?: number): number;
8
+ //# 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,EACV,oBAAoB,EACpB,oBAAoB,EAEpB,4BAA4B,EAE7B,MAAM,SAAS,CAAA;AAChB,wBAAgB,aAAa,CAAC,KAAK,EAAE,oBAAoB,GAAG,oBAAoB,GAAG,IAAI,CA4CtF;AACD,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,MAAM,CAMR;AACD,wBAAgB,aAAa,CAAC,KAAK,EAAE,oBAAoB,GAAG,4BAA4B,CA2IvF;AACD,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,MAAM,CAMR;AACD,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,GACjB,MAAM,CAER;AACD,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAgB1E"}
@@ -0,0 +1,7 @@
1
+ import type { Currency, CurrencyConfig } from './types';
2
+ export declare const CURRENCY_CONFIG: Record<Currency, CurrencyConfig>;
3
+ export declare function formatCurrency(currency: Currency, amount: number): string;
4
+ export declare function getCurrencyConfig(currency: Currency): CurrencyConfig;
5
+ export declare function getSupportedCurrencies(): Currency[];
6
+ export declare function getCurrenciesByRegion(region: CurrencyConfig['region']): Currency[];
7
+ //# sourceMappingURL=currency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../src/currency.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACvD,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,QAAQ,EAAE,cAAc,CAyW5D,CAAA;AACD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAiBzE;AACD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAEpE;AACD,wBAAgB,sBAAsB,IAAI,QAAQ,EAAE,CAEnD;AACD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,GAAG,QAAQ,EAAE,CAIlF"}