moneyfunx 0.0.38 → 0.0.39

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.
@@ -40,10 +40,10 @@ export function amortizePayments(loan, principal, payment, numPayments, startPer
40
40
  numPayments = loan.numPaymentsToZero(payment);
41
41
  }
42
42
  let principalRemaining = principal;
43
- let amortizationSchedule = [];
43
+ const amortizationSchedule = [];
44
44
  for (let period = 0; period < numPayments; period++) {
45
- let interestThisPeriod = loan.accrueInterest(principalRemaining);
46
- let principalThisPeriod = Math.min((period === numPayments - 1 ? payment + carryover : payment) - interestThisPeriod, principalRemaining);
45
+ const interestThisPeriod = loan.accrueInterest(principalRemaining);
46
+ const principalThisPeriod = Math.min((period === numPayments - 1 ? payment + carryover : payment) - interestThisPeriod, principalRemaining);
47
47
  principalRemaining -= principalThisPeriod;
48
48
  amortizationSchedule.push({
49
49
  period: startPeriod + period + 1,
@@ -83,7 +83,7 @@ export function payLoans(loans, payment, reduceMinimum = false) {
83
83
  const firstLoanPrincipalRemaining = loanPrincipalsRemaining[firstLoan.id];
84
84
  const periodsToPay = helpers.numPaymentsToZero(firstLoanPrincipalRemaining, firstLoanPayment, firstLoan.periodicRate);
85
85
  const firstLoanPaidPeriods = amortizePayments(firstLoan, firstLoanPrincipalRemaining, firstLoanPayment, periodsToPay, periodsElapsed);
86
- const firstLoanCarryover = firstLoanPayment - firstLoan.principalRemaining(periodsToPay - 1, firstLoanPayment, firstLoanPrincipalRemaining);
86
+ const firstLoanCarryover = firstLoanPayment - (firstLoan.principalRemaining(periodsToPay - 1, firstLoanPayment, firstLoanPrincipalRemaining) + firstLoan.accrueInterest(firstLoan.principalRemaining(periodsToPay - 1, firstLoanPayment, firstLoanPrincipalRemaining)));
87
87
  paymentData[firstLoan.id].amortizationSchedule = [
88
88
  ...paymentData[firstLoan.id].amortizationSchedule,
89
89
  ...firstLoanPaidPeriods
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "moneyfunx",
3
3
  "type": "module",
4
- "version": "0.0.38",
4
+ "version": "0.0.39",
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",
@@ -68,10 +68,10 @@ export function amortizePayments(
68
68
 
69
69
  let principalRemaining = principal;
70
70
 
71
- let amortizationSchedule: AmortizationRecord[] = [];
71
+ const amortizationSchedule: AmortizationRecord[] = [];
72
72
  for (let period = 0; period < numPayments; period++) {
73
- let interestThisPeriod = loan.accrueInterest(principalRemaining);
74
- let principalThisPeriod = Math.min(
73
+ const interestThisPeriod = loan.accrueInterest(principalRemaining);
74
+ const principalThisPeriod = Math.min(
75
75
  (period === numPayments - 1 ? payment + carryover : payment) - interestThisPeriod,
76
76
  principalRemaining
77
77
  );
@@ -132,10 +132,18 @@ export function payLoans(
132
132
  periodsToPay,
133
133
  periodsElapsed
134
134
  );
135
- const firstLoanCarryover = firstLoanPayment - firstLoan.principalRemaining(
136
- periodsToPay - 1,
137
- firstLoanPayment,
138
- firstLoanPrincipalRemaining
135
+ const firstLoanCarryover = firstLoanPayment - (
136
+ firstLoan.principalRemaining(
137
+ periodsToPay - 1,
138
+ firstLoanPayment,
139
+ firstLoanPrincipalRemaining
140
+ ) + firstLoan.accrueInterest(
141
+ firstLoan.principalRemaining(
142
+ periodsToPay - 1,
143
+ firstLoanPayment,
144
+ firstLoanPrincipalRemaining
145
+ )
146
+ )
139
147
  );
140
148
  paymentData[firstLoan.id].amortizationSchedule = [
141
149
  ...paymentData[firstLoan.id].amortizationSchedule,