moneyfunx 0.0.40 → 0.0.43

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.
@@ -64,7 +64,7 @@ export declare class Loan implements ILoan {
64
64
  * Calculates the number of payments needed to pay off a principal at a provided payemnt amount
65
65
  * @param {number} payment The amount to pay the loan with
66
66
  * @param {number} principal The amout of money owed on a loan
67
- * @returns {number} The number of payments neede to pay the loan off
67
+ * @returns {number} The number of payments needed to pay the loan off
68
68
  */
69
69
  numPaymentsToZero(payment?: number, principal?: number): number;
70
70
  /**
package/build/lib/loan.js CHANGED
@@ -64,7 +64,7 @@ export class Loan {
64
64
  * Calculates the number of payments needed to pay off a principal at a provided payemnt amount
65
65
  * @param {number} payment The amount to pay the loan with
66
66
  * @param {number} principal The amout of money owed on a loan
67
- * @returns {number} The number of payments neede to pay the loan off
67
+ * @returns {number} The number of payments needed to pay the loan off
68
68
  */
69
69
  numPaymentsToZero(payment = this.minPayment, principal = this.principal) {
70
70
  this.validatePayment(payment);
@@ -16,7 +16,8 @@ import * as helpers from "./helperFunctions";
16
16
  */
17
17
  export function determineExtraPayment(loans, payment) {
18
18
  const totalMinPayment = loans.reduce((previousValue, currentValue) => previousValue + currentValue.minPayment, 0);
19
- if (totalMinPayment > payment) {
19
+ // hack to get around floating precision adjustments
20
+ if (parseFloat(totalMinPayment.toFixed(2)) > parseFloat(payment.toFixed(2))) {
20
21
  throw new errors.PaymentTooLowError(`Payment amount of ${payment} must be greater than ${totalMinPayment}`);
21
22
  }
22
23
  return payment - totalMinPayment;
@@ -101,7 +102,7 @@ export function payLoans(loans, payment, reduceMinimum = false) {
101
102
  ];
102
103
  paidLoans += 1;
103
104
  // handle calculating information for the rest of the loans
104
- loans.slice(paidLoans).map((loan, index) => {
105
+ loans.slice(paidLoans).forEach((loan, index) => {
105
106
  const loanPrincipalRemaining = loanPrincipalsRemaining[loan.id];
106
107
  const paidPeriods = amortizePayments(loan, loanPrincipalRemaining, loan.minPayment, periodsToPay, periodsElapsed, index === 0 ? firstLoanCarryover : 0);
107
108
  paymentData[loan.id].amortizationSchedule = [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "moneyfunx",
3
3
  "type": "module",
4
- "version": "0.0.40",
4
+ "version": "0.0.43",
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
@@ -105,7 +105,7 @@ export class Loan implements ILoan {
105
105
  * Calculates the number of payments needed to pay off a principal at a provided payemnt amount
106
106
  * @param {number} payment The amount to pay the loan with
107
107
  * @param {number} principal The amout of money owed on a loan
108
- * @returns {number} The number of payments neede to pay the loan off
108
+ * @returns {number} The number of payments needed to pay the loan off
109
109
  */
110
110
  numPaymentsToZero(
111
111
  payment: number = this.minPayment,
@@ -30,7 +30,8 @@ export function determineExtraPayment(
30
30
  (previousValue, currentValue) => previousValue + currentValue.minPayment,
31
31
  0
32
32
  );
33
- if (totalMinPayment > payment) {
33
+ // hack to get around floating precision adjustments
34
+ if (parseFloat(totalMinPayment.toFixed(2)) > parseFloat(payment.toFixed(2))) {
34
35
  throw new errors.PaymentTooLowError(
35
36
  `Payment amount of ${payment} must be greater than ${totalMinPayment}`
36
37
  );
@@ -161,7 +162,7 @@ export function payLoans(
161
162
  ];
162
163
  paidLoans += 1;
163
164
  // handle calculating information for the rest of the loans
164
- loans.slice(paidLoans).map((loan, index) => {
165
+ loans.slice(paidLoans).forEach((loan, index) => {
165
166
  const loanPrincipalRemaining = loanPrincipalsRemaining[loan.id];
166
167
  const paidPeriods = amortizePayments(
167
168
  loan,