moneyfunx 1.0.9 → 1.0.12

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.
@@ -21,8 +21,8 @@ export interface ILoan {
21
21
  periodicRate: number;
22
22
  periods: number;
23
23
  minPayment: number;
24
- name?: string;
25
24
  currentBalance: number;
25
+ name?: string;
26
26
  }
27
27
  export declare class Loan implements ILoan {
28
28
  id: string;
@@ -33,8 +33,8 @@ export declare class Loan implements ILoan {
33
33
  periodicRate: number;
34
34
  periods: number;
35
35
  minPayment: number;
36
- name?: string;
37
36
  currentBalance: number;
37
+ name?: string;
38
38
  /**
39
39
  * @constructor
40
40
  * @param {number} principal The amount borrowed
package/build/lib/loan.js CHANGED
@@ -41,7 +41,7 @@ export class Loan {
41
41
  * @returns {number} The validated payment amount
42
42
  */
43
43
  validatePayment(payment = this.minPayment) {
44
- if (payment < this.minPayment) {
44
+ if (parseInt((100 * this.minPayment).toFixed()) > parseInt((100 * payment).toFixed())) {
45
45
  throw new errors.PaymentTooLowError(`payment of ${payment} cannot be less than ${this.minPayment}`);
46
46
  }
47
47
  return payment;
@@ -17,7 +17,7 @@ import * as helpers from './helperFunctions';
17
17
  export function determineExtraPayment(loans, payment) {
18
18
  const totalMinPayment = loans.reduce((previousValue, currentValue) => previousValue + currentValue.minPayment, 0);
19
19
  // hack to get around floating precision adjustments
20
- if (parseFloat(totalMinPayment.toFixed(2)) > parseFloat(payment.toFixed(2))) {
20
+ if (parseInt((100 * totalMinPayment).toFixed()) > parseInt((100 * payment).toFixed())) {
21
21
  throw new errors.PaymentTooLowError(`Payment amount of ${payment} must be greater than ${totalMinPayment}`);
22
22
  }
23
23
  return payment - totalMinPayment;
@@ -106,7 +106,7 @@ export function payLoans(loans, payment, reduceMinimum = false) {
106
106
  // handle calculating information for the rest of the loans
107
107
  loans.slice(paidLoans).forEach((loan, index) => {
108
108
  const loanPrincipalRemaining = loanPrincipalsRemaining[loan.id];
109
- const paidPeriods = amortizePayments(loan, loanPrincipalRemaining, loan.minPayment, periodsToPay, periodsElapsed, index === 0 ? firstLoanCarryover : 0);
109
+ const paidPeriods = amortizePayments(loan, loanPrincipalRemaining, loan.minPayment, periodsToPay, periodsElapsed, (index === 0 && !reduceMinimum) ? firstLoanCarryover : 0);
110
110
  paymentData[loan.id].amortizationSchedule = [
111
111
  ...paymentData[loan.id].amortizationSchedule,
112
112
  ...paidPeriods,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "moneyfunx",
3
3
  "type": "module",
4
- "version": "1.0.9",
4
+ "version": "1.0.12",
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
@@ -25,8 +25,8 @@ export interface ILoan {
25
25
  periodicRate: number;
26
26
  periods: number;
27
27
  minPayment: number;
28
- name?: string;
29
28
  currentBalance: number;
29
+ name?: string;
30
30
  }
31
31
 
32
32
  export class Loan implements ILoan {
@@ -38,8 +38,8 @@ export class Loan implements ILoan {
38
38
  periodicRate: number;
39
39
  periods: number;
40
40
  minPayment: number;
41
- name?: string;
42
41
  currentBalance: number;
42
+ name?: string;
43
43
 
44
44
  /**
45
45
  * @constructor
@@ -78,7 +78,7 @@ export class Loan implements ILoan {
78
78
  * @returns {number} The validated payment amount
79
79
  */
80
80
  validatePayment(payment: number = this.minPayment): number {
81
- if (payment < this.minPayment) {
81
+ if (parseInt((100 * this.minPayment).toFixed()) > parseInt((100 * payment).toFixed())) {
82
82
  throw new errors.PaymentTooLowError(
83
83
  `payment of ${payment} cannot be less than ${this.minPayment}`
84
84
  );
@@ -31,7 +31,7 @@ export function determineExtraPayment(
31
31
  0
32
32
  );
33
33
  // hack to get around floating precision adjustments
34
- if (parseFloat(totalMinPayment.toFixed(2)) > parseFloat(payment.toFixed(2))) {
34
+ if (parseInt((100 * totalMinPayment).toFixed()) > parseInt((100 * payment).toFixed())) {
35
35
  throw new errors.PaymentTooLowError(
36
36
  `Payment amount of ${payment} must be greater than ${totalMinPayment}`
37
37
  );
@@ -172,7 +172,7 @@ export function payLoans(
172
172
  loan.minPayment,
173
173
  periodsToPay,
174
174
  periodsElapsed,
175
- index === 0 ? firstLoanCarryover : 0
175
+ (index === 0 && !reduceMinimum) ? firstLoanCarryover : 0
176
176
  );
177
177
  paymentData[loan.id].amortizationSchedule = [
178
178
  ...paymentData[loan.id].amortizationSchedule,