moneyfunx 1.0.10 → 1.0.13
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.d.ts +5 -3
- package/build/lib/loan.js +3 -2
- package/build/lib/payments.js +1 -1
- package/package.json +1 -1
- package/src/lib/loan.ts +7 -3
- package/src/lib/payments.ts +1 -1
package/build/lib/loan.d.ts
CHANGED
|
@@ -21,8 +21,9 @@ export interface ILoan {
|
|
|
21
21
|
periodicRate: number;
|
|
22
22
|
periods: number;
|
|
23
23
|
minPayment: number;
|
|
24
|
-
name?: string;
|
|
25
24
|
currentBalance: number;
|
|
25
|
+
fees: number;
|
|
26
|
+
name?: string;
|
|
26
27
|
}
|
|
27
28
|
export declare class Loan implements ILoan {
|
|
28
29
|
id: string;
|
|
@@ -33,8 +34,9 @@ export declare class Loan implements ILoan {
|
|
|
33
34
|
periodicRate: number;
|
|
34
35
|
periods: number;
|
|
35
36
|
minPayment: number;
|
|
36
|
-
name?: string;
|
|
37
37
|
currentBalance: number;
|
|
38
|
+
fees: number;
|
|
39
|
+
name?: string;
|
|
38
40
|
/**
|
|
39
41
|
* @constructor
|
|
40
42
|
* @param {number} principal The amount borrowed
|
|
@@ -44,7 +46,7 @@ export declare class Loan implements ILoan {
|
|
|
44
46
|
* @param {number} name (Optional) The name for the loan
|
|
45
47
|
* @param {number} currentBalance (Optional) The current balance of the loan, if different from the principal
|
|
46
48
|
*/
|
|
47
|
-
constructor(principal: number, annualRate: number, periodsPerYear: number, termInYears: number, name?: string, currentBalance?: number);
|
|
49
|
+
constructor(principal: number, annualRate: number, periodsPerYear: number, termInYears: number, name?: string, currentBalance?: number, fees?: number);
|
|
48
50
|
/**
|
|
49
51
|
* Verifies a payment amount is valid
|
|
50
52
|
* Throws a PaymentTooLowError if the payment amount is less than the loan's minimum payment
|
package/build/lib/loan.js
CHANGED
|
@@ -21,7 +21,7 @@ export class Loan {
|
|
|
21
21
|
* @param {number} name (Optional) The name for the loan
|
|
22
22
|
* @param {number} currentBalance (Optional) The current balance of the loan, if different from the principal
|
|
23
23
|
*/
|
|
24
|
-
constructor(principal, annualRate, periodsPerYear, termInYears, name, currentBalance) {
|
|
24
|
+
constructor(principal, annualRate, periodsPerYear, termInYears, name, currentBalance, fees) {
|
|
25
25
|
this.id = String(Math.floor(Math.random() * Date.now()));
|
|
26
26
|
this.principal = principal;
|
|
27
27
|
this.annualRate = annualRate;
|
|
@@ -32,6 +32,7 @@ export class Loan {
|
|
|
32
32
|
this.minPayment = this.calculateMinPayment();
|
|
33
33
|
this.name = name;
|
|
34
34
|
this.currentBalance = currentBalance || principal;
|
|
35
|
+
this.fees = fees || 0;
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
37
38
|
* Verifies a payment amount is valid
|
|
@@ -41,7 +42,7 @@ export class Loan {
|
|
|
41
42
|
* @returns {number} The validated payment amount
|
|
42
43
|
*/
|
|
43
44
|
validatePayment(payment = this.minPayment) {
|
|
44
|
-
if (
|
|
45
|
+
if (parseInt((100 * this.minPayment).toFixed()) > parseInt((100 * payment).toFixed())) {
|
|
45
46
|
throw new errors.PaymentTooLowError(`payment of ${payment} cannot be less than ${this.minPayment}`);
|
|
46
47
|
}
|
|
47
48
|
return payment;
|
package/build/lib/payments.js
CHANGED
|
@@ -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 (
|
|
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;
|
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.13",
|
|
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,9 @@ export interface ILoan {
|
|
|
25
25
|
periodicRate: number;
|
|
26
26
|
periods: number;
|
|
27
27
|
minPayment: number;
|
|
28
|
-
name?: string;
|
|
29
28
|
currentBalance: number;
|
|
29
|
+
fees: number;
|
|
30
|
+
name?: string;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
export class Loan implements ILoan {
|
|
@@ -38,8 +39,9 @@ export class Loan implements ILoan {
|
|
|
38
39
|
periodicRate: number;
|
|
39
40
|
periods: number;
|
|
40
41
|
minPayment: number;
|
|
41
|
-
name?: string;
|
|
42
42
|
currentBalance: number;
|
|
43
|
+
fees: number;
|
|
44
|
+
name?: string;
|
|
43
45
|
|
|
44
46
|
/**
|
|
45
47
|
* @constructor
|
|
@@ -57,6 +59,7 @@ export class Loan implements ILoan {
|
|
|
57
59
|
termInYears: number,
|
|
58
60
|
name?: string,
|
|
59
61
|
currentBalance?: number,
|
|
62
|
+
fees?: number,
|
|
60
63
|
) {
|
|
61
64
|
this.id = String(Math.floor(Math.random() * Date.now()));
|
|
62
65
|
this.principal = principal;
|
|
@@ -68,6 +71,7 @@ export class Loan implements ILoan {
|
|
|
68
71
|
this.minPayment = this.calculateMinPayment();
|
|
69
72
|
this.name = name;
|
|
70
73
|
this.currentBalance = currentBalance || principal;
|
|
74
|
+
this.fees = fees || 0;
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
/**
|
|
@@ -78,7 +82,7 @@ export class Loan implements ILoan {
|
|
|
78
82
|
* @returns {number} The validated payment amount
|
|
79
83
|
*/
|
|
80
84
|
validatePayment(payment: number = this.minPayment): number {
|
|
81
|
-
if (
|
|
85
|
+
if (parseInt((100 * this.minPayment).toFixed()) > parseInt((100 * payment).toFixed())) {
|
|
82
86
|
throw new errors.PaymentTooLowError(
|
|
83
87
|
`payment of ${payment} cannot be less than ${this.minPayment}`
|
|
84
88
|
);
|
package/src/lib/payments.ts
CHANGED
|
@@ -31,7 +31,7 @@ export function determineExtraPayment(
|
|
|
31
31
|
0
|
|
32
32
|
);
|
|
33
33
|
// hack to get around floating precision adjustments
|
|
34
|
-
if (
|
|
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
|
);
|