moneyfunx 0.0.7 → 0.0.11
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/package.json +6 -5
- package/src/index.js +3 -3
- package/src/lib/loan.js +0 -3
- package/src/lib/payments.js +6 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moneyfunx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.11",
|
|
5
5
|
"description": "MoneyFunx is a small library of functions for financial computations, with a focus on personal finance",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -9,13 +9,14 @@
|
|
|
9
9
|
"lint": "eslint"
|
|
10
10
|
},
|
|
11
11
|
"author": "Kyle Pekosh",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/Kylep342/moneyfunx.git"
|
|
15
|
+
},
|
|
12
16
|
"license": "MIT",
|
|
13
17
|
"devDependencies": {
|
|
14
18
|
"eslint": "^8.11.0",
|
|
15
19
|
"eslint-plugin-vue": "^8.5.0",
|
|
16
20
|
"jest": "^27.5.1"
|
|
17
|
-
}
|
|
18
|
-
"publishConfig": {
|
|
19
|
-
"@Kylep342:registry": "https://npm.pkg.github.com"
|
|
20
|
-
}
|
|
21
|
+
}
|
|
21
22
|
}
|
package/src/index.js
CHANGED
|
@@ -3,14 +3,14 @@ export {
|
|
|
3
3
|
principalRemaining,
|
|
4
4
|
numPaymentsToZero,
|
|
5
5
|
Loan
|
|
6
|
-
} from "lib/loan
|
|
6
|
+
} from "./lib/loan";
|
|
7
7
|
export {
|
|
8
8
|
determineExtraPayment,
|
|
9
9
|
amortizePayments,
|
|
10
10
|
payLoans
|
|
11
|
-
} from "lib/payments
|
|
11
|
+
} from "./lib/payments";
|
|
12
12
|
export {
|
|
13
13
|
snowball,
|
|
14
14
|
avalanche,
|
|
15
15
|
sortLoans
|
|
16
|
-
} from "lib/sorting
|
|
16
|
+
} from "./lib/sorting";
|
package/src/lib/loan.js
CHANGED
|
@@ -41,7 +41,6 @@ export function numPaymentsToZero (principal, payment, periodicRate) {
|
|
|
41
41
|
);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
//
|
|
45
44
|
export class Loan {
|
|
46
45
|
constructor (principal, annualRate, periodsPerYear, termInYears) {
|
|
47
46
|
this.id = String(Math.floor(Math.random() * Date.now()));
|
|
@@ -68,8 +67,6 @@ export class Loan {
|
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
accrueInterest(balance=this.principal) {
|
|
71
|
-
// TODO: figure out if this is valid
|
|
72
|
-
// UPDATE: 24-3-2022 this is valid AF
|
|
73
70
|
return balance * this.periodicRate;
|
|
74
71
|
}
|
|
75
72
|
|
package/src/lib/payments.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
2
|
|
|
3
3
|
*/
|
|
4
|
-
import * as loanLib from "./loan
|
|
4
|
+
import * as loanLib from "./loan";
|
|
5
5
|
|
|
6
|
-
//
|
|
7
6
|
export function determineExtraPayment (loans, payment) {
|
|
8
7
|
const totalMinPayment = loans.reduce(
|
|
9
8
|
(previousValue, currentValue) => previousValue + currentValue.minPayment,
|
|
@@ -15,7 +14,6 @@ export function determineExtraPayment (loans, payment) {
|
|
|
15
14
|
return payment - totalMinPayment;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
//
|
|
19
17
|
export function amortizePayments (loan, payment, numPayments, startPeriod) {
|
|
20
18
|
payment = loan.validatePayment(payment);
|
|
21
19
|
let amortizationSchedule = [];
|
|
@@ -55,7 +53,7 @@ export function amortizePayments (loan, payment, numPayments, startPeriod) {
|
|
|
55
53
|
return amortizationSchedule;
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
//
|
|
56
|
+
// TODO: What if this returns a list?
|
|
59
57
|
export function payLoans (loans, payment) {
|
|
60
58
|
let loanInterestTotals = {};
|
|
61
59
|
loans.map(
|
|
@@ -66,6 +64,7 @@ export function payLoans (loans, payment) {
|
|
|
66
64
|
|
|
67
65
|
let periodsElapsed = 0;
|
|
68
66
|
let paidLoans = 0;
|
|
67
|
+
let totalInterest = 0;
|
|
69
68
|
|
|
70
69
|
while (paidLoans < loans.length) {
|
|
71
70
|
let extraPaymentAmount = determineExtraPayment(loans.slice(paidLoans), payment);
|
|
@@ -85,6 +84,7 @@ export function payLoans (loans, payment) {
|
|
|
85
84
|
firstLoan.principalRemaining(periodsElapsed)
|
|
86
85
|
);
|
|
87
86
|
loanInterestTotals[firstLoan.id].lifetimeInterest += firstLoanInterestPaid;
|
|
87
|
+
totalInterest += loanInterestTotals[firstLoan.id].lifetimeInterest;
|
|
88
88
|
loanInterestTotals[firstLoan.id].amortizationSchedule = [
|
|
89
89
|
...loanInterestTotals[firstLoan.id].amortizationSchedule,
|
|
90
90
|
...amortizePayments(firstLoan, firstLoanPayment, periodsToPay, periodsElapsed)
|
|
@@ -96,6 +96,7 @@ export function payLoans (loans, payment) {
|
|
|
96
96
|
loan.minPayment,
|
|
97
97
|
loan.principalRemaining(periodsElapsed)
|
|
98
98
|
);
|
|
99
|
+
totalInterest += loanInterestTotals[loan.id].lifetimeInterest;
|
|
99
100
|
loanInterestTotals[loan.id].amortizationSchedule = [
|
|
100
101
|
...loanInterestTotals[loan.id].amortizationSchedule,
|
|
101
102
|
...amortizePayments(loan, loan.minPayment, periodsToPay, periodsElapsed)
|
|
@@ -103,5 +104,6 @@ export function payLoans (loans, payment) {
|
|
|
103
104
|
});
|
|
104
105
|
periodsElapsed += periodsToPay;
|
|
105
106
|
}
|
|
107
|
+
loanInterestTotals["totalInterest"] = totalInterest;
|
|
106
108
|
return loanInterestTotals;
|
|
107
109
|
}
|