moneyfunx 1.0.0 → 1.0.1
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/build/lib/loan.js +5 -7
- package/build/lib/payments.d.ts +1 -0
- package/build/lib/payments.js +1 -0
- package/package.json +1 -1
- package/src/lib/loan.ts +5 -6
- package/src/lib/payments.ts +1 -0
package/build/lib/loan.js
CHANGED
|
@@ -42,9 +42,7 @@ export class Loan {
|
|
|
42
42
|
if (payment < this.minPayment) {
|
|
43
43
|
throw new errors.PaymentTooLowError(`payment of ${payment} cannot be less than ${this.minPayment}`);
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
return payment;
|
|
47
|
-
}
|
|
45
|
+
return payment;
|
|
48
46
|
}
|
|
49
47
|
/**
|
|
50
48
|
* Calculates the minimum payment to pay off the loan in the required number of periods
|
|
@@ -93,10 +91,10 @@ export class Loan {
|
|
|
93
91
|
*/
|
|
94
92
|
interestPaid(periods, payment = this.minPayment, principal = this.principal) {
|
|
95
93
|
this.validatePayment(payment);
|
|
96
|
-
const
|
|
97
|
-
return periods <
|
|
94
|
+
const paymentsToZero = this.numPaymentsToZero(payment, principal);
|
|
95
|
+
return periods < paymentsToZero
|
|
98
96
|
? helpers.interestPaid(principal, payment, this.periodicRate, periods)
|
|
99
|
-
: helpers.interestPaid(principal, payment, this.periodicRate,
|
|
100
|
-
this.accrueInterest(this.principalRemaining(
|
|
97
|
+
: helpers.interestPaid(principal, payment, this.periodicRate, paymentsToZero - 1) +
|
|
98
|
+
this.accrueInterest(this.principalRemaining(paymentsToZero - 1, payment, principal));
|
|
101
99
|
}
|
|
102
100
|
}
|
package/build/lib/payments.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare function determineExtraPayment(loans: ILoan[], payment: number):
|
|
|
23
23
|
* @param {number} payment The amount to pay to the loan's balance each period
|
|
24
24
|
* @param {number} numPayments The number of periods to make payments to the loan
|
|
25
25
|
* @param {number} startPeriod An initial offset of periods to 'fast-forward' the state of the loan to prior to calculation of each period
|
|
26
|
+
* @param {number} carryover An additional amount to pay towards a loan, used when a residual amount is available from paying off the previous loan this period
|
|
26
27
|
* @returns {Array<AmortizationRecord>} The amortization schdule for the number of payments of payment made to the loan from the provided start period
|
|
27
28
|
*/
|
|
28
29
|
export declare function amortizePayments(loan: Loan, principal: number, payment: number, numPayments: number, startPeriod?: number, carryover?: number): AmortizationRecord[];
|
package/build/lib/payments.js
CHANGED
|
@@ -30,6 +30,7 @@ export function determineExtraPayment(loans, payment) {
|
|
|
30
30
|
* @param {number} payment The amount to pay to the loan's balance each period
|
|
31
31
|
* @param {number} numPayments The number of periods to make payments to the loan
|
|
32
32
|
* @param {number} startPeriod An initial offset of periods to 'fast-forward' the state of the loan to prior to calculation of each period
|
|
33
|
+
* @param {number} carryover An additional amount to pay towards a loan, used when a residual amount is available from paying off the previous loan this period
|
|
33
34
|
* @returns {Array<AmortizationRecord>} The amortization schdule for the number of payments of payment made to the loan from the provided start period
|
|
34
35
|
*/
|
|
35
36
|
export function amortizePayments(loan, principal, payment, numPayments, startPeriod = 0, carryover = 0) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moneyfunx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"description": "MoneyFunx is a small library of functions for financial computations, with a focus on personal finance",
|
|
6
6
|
"main": "build/index.js",
|
|
7
7
|
"types": "build/index.d.ts",
|
package/src/lib/loan.ts
CHANGED
|
@@ -79,9 +79,8 @@ export class Loan implements ILoan {
|
|
|
79
79
|
throw new errors.PaymentTooLowError(
|
|
80
80
|
`payment of ${payment} cannot be less than ${this.minPayment}`
|
|
81
81
|
);
|
|
82
|
-
} else {
|
|
83
|
-
return payment;
|
|
84
82
|
}
|
|
83
|
+
return payment;
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
/**
|
|
@@ -155,17 +154,17 @@ export class Loan implements ILoan {
|
|
|
155
154
|
principal: number = this.principal
|
|
156
155
|
): number {
|
|
157
156
|
this.validatePayment(payment);
|
|
158
|
-
const
|
|
159
|
-
return periods <
|
|
157
|
+
const paymentsToZero = this.numPaymentsToZero(payment, principal);
|
|
158
|
+
return periods < paymentsToZero
|
|
160
159
|
? helpers.interestPaid(principal, payment, this.periodicRate, periods)
|
|
161
160
|
: helpers.interestPaid(
|
|
162
161
|
principal,
|
|
163
162
|
payment,
|
|
164
163
|
this.periodicRate,
|
|
165
|
-
|
|
164
|
+
paymentsToZero - 1
|
|
166
165
|
) +
|
|
167
166
|
this.accrueInterest(
|
|
168
|
-
this.principalRemaining(
|
|
167
|
+
this.principalRemaining(paymentsToZero - 1, payment, principal)
|
|
169
168
|
);
|
|
170
169
|
}
|
|
171
170
|
}
|
package/src/lib/payments.ts
CHANGED
|
@@ -47,6 +47,7 @@ export function determineExtraPayment(
|
|
|
47
47
|
* @param {number} payment The amount to pay to the loan's balance each period
|
|
48
48
|
* @param {number} numPayments The number of periods to make payments to the loan
|
|
49
49
|
* @param {number} startPeriod An initial offset of periods to 'fast-forward' the state of the loan to prior to calculation of each period
|
|
50
|
+
* @param {number} carryover An additional amount to pay towards a loan, used when a residual amount is available from paying off the previous loan this period
|
|
50
51
|
* @returns {Array<AmortizationRecord>} The amortization schdule for the number of payments of payment made to the loan from the provided start period
|
|
51
52
|
*/
|
|
52
53
|
export function amortizePayments(
|