+5
-18
| "use strict"; | ||
| function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
| function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
| (function () { | ||
| 'use strict'; | ||
| /* | ||
@@ -22,6 +22,6 @@ * LoanJS | ||
| */ | ||
| function rnd(num) { | ||
| return Math.round(num * 100) / 100; | ||
| } | ||
| /* | ||
@@ -47,4 +47,2 @@ * LoanJS | ||
| */ | ||
| var getNextInstalment = function getNextInstalment(amount, installmentsNumber, interestRate, diminishing, capitalSum, interestSum) { | ||
@@ -56,3 +54,2 @@ var capital; | ||
| var interestRateMonth = interestRate / 1200; | ||
| if (diminishing) { | ||
@@ -68,3 +65,2 @@ capital = rnd(amount / installmentsNumber); | ||
| } | ||
| return { | ||
@@ -78,2 +74,3 @@ capital: capital, | ||
| }; | ||
| /** | ||
@@ -89,7 +86,4 @@ * Create Loan Object with all installments and sum of interest | ||
| */ | ||
| function Loan(amount, installmentsNumber, interestRate) { | ||
| var diminishing = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
| /** Checking params */ | ||
@@ -99,3 +93,2 @@ if (!amount || amount <= 0 || !installmentsNumber || installmentsNumber <= 0 || !interestRate || interestRate <= 0) { | ||
| } | ||
| var installments = []; | ||
@@ -105,3 +98,2 @@ var interestSum = 0; | ||
| var sum = 0; | ||
| for (var i = 0; i < installmentsNumber; i++) { | ||
@@ -113,3 +105,2 @@ var inst = getNextInstalment(amount, installmentsNumber, interestRate, diminishing, capitalSum, interestSum); | ||
| /** adding lost sum on rounding */ | ||
| if (i === installmentsNumber - 1) { | ||
@@ -120,6 +111,4 @@ capitalSum += inst.remain; | ||
| } | ||
| installments.push(inst); | ||
| } | ||
| return { | ||
@@ -133,5 +122,4 @@ installments: installments, | ||
| } | ||
| /* istanbul ignore next */ | ||
| if (typeof module === 'undefined') { | ||
@@ -145,3 +133,2 @@ // browser | ||
| } | ||
| window.LoanJS.Loan = Loan; | ||
@@ -148,0 +135,0 @@ } |
+1
-1
@@ -1,1 +0,1 @@ | ||
| "use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}!function(){function w(t){return Math.round(100*t)/100}function t(t,n,o){var e=3<arguments.length&&void 0!==arguments[3]&&arguments[3];if(!t||t<=0||!n||n<=0||!o||o<=0)throw new Error("wrong parameters: ".concat(t," ").concat(n," ").concat(o));for(var r,i,a,u,f,m,c,l=[],p=0,y=0,s=0,S=0;S<n;S++){var d=(r=t,i=n,a=o,u=y,f=p,c=d=m=void 0,a/=1200,e?c=(m=w(r/i))+(d=w((r-u)*a)):m=(c=w(r*(a*(i=Math.pow(1+a,i))/(i-1))))-(d=w((r-u)*a)),{capital:m,interest:d,installment:c,remain:r-u-m,interestSum:f+d});s+=d.installment,y+=d.capital,p+=d.interest,S===n-1&&(y+=d.remain,s+=d.remain,d.remain=0),l.push(d)}return{installments:l,amount:w(t),interestSum:w(p),capitalSum:w(y),sum:w(s)}}"undefined"==typeof module?"object"===("undefined"==typeof LOANJS_NAMESPACE?"undefined":_typeof(LOANJS_NAMESPACE))?LOANJS_NAMESPACE.Loan=t:(window.LoanJS||(window.LoanJS={}),window.LoanJS.Loan=t):module.exports=t}(); | ||
| "use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}!function(){function A(t){return Math.round(100*t)/100}function t(t,n,o){var e=3<arguments.length&&void 0!==arguments[3]&&arguments[3];if(!t||t<=0||!n||n<=0||!o||o<=0)throw new Error("wrong parameters: ".concat(t," ").concat(n," ").concat(o));for(var r,i,a,u,f,m,c,l,p=[],y=0,s=0,S=0,d=0;d<n;d++){r=t,w=n,i=o,u=s,f=y,l=c=m=void 0,i/=1200,(a=e)?l=(m=A(r/w))+(c=A((r-u)*i)):m=(l=A(r*(i*(a=Math.pow(1+i,w))/(a-1))))-(c=A((r-u)*i));var w={capital:m,interest:c,installment:l,remain:r-u-m,interestSum:f+c};S+=w.installment,s+=w.capital,y+=w.interest,d===n-1&&(s+=w.remain,S+=w.remain,w.remain=0),p.push(w)}return{installments:p,amount:A(t),interestSum:A(y),capitalSum:A(s),sum:A(S)}}"undefined"==typeof module?"object"===("undefined"==typeof LOANJS_NAMESPACE?"undefined":_typeof(LOANJS_NAMESPACE))?LOANJS_NAMESPACE.Loan=t:(window.LoanJS||(window.LoanJS={}),window.LoanJS.Loan=t):module.exports=t}(); |
| "use strict"; | ||
| function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
| function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
| (function () { | ||
| 'use strict'; | ||
| /** | ||
@@ -14,12 +14,8 @@ * Create Loan Object with all installments and sum of interest | ||
| */ | ||
| function loanToHtmlTable(loan, params) { | ||
| params = params || {}; | ||
| params.formatMoney = params.formatMoney || function (num) { | ||
| return num.toFixed(2); | ||
| }; | ||
| var fm = params.formatMoney; | ||
| var trans = function trans(key) { | ||
@@ -32,6 +28,5 @@ if (params.translations && params.translations[key]) { | ||
| }; | ||
| var html = ['<table>' + '<thead>' + '<tr>' + '<th></th>' + '<th>' + trans('Capital') + '</th>' + '<th>' + trans('Interest') + '</th>' + '<th>' + trans('Instalment') + '</th>' + '<th>' + trans('Remain') + '</th>' + '<th>' + trans('Interest sum') + '</th>' + '</tr>' + '</thead>' + '<tbody>', '', // body content [1] | ||
| var html = ['<table>' + '<thead>' + '<tr>' + '<th></th>' + '<th>' + trans('Capital') + '</th>' + '<th>' + trans('Interest') + '</th>' + '<th>' + trans('Instalment') + '</th>' + '<th>' + trans('Remain') + '</th>' + '<th>' + trans('Interest sum') + '</th>' + '</tr>' + '</thead>' + '<tbody>', '', | ||
| // body content [1] | ||
| '</tbody>' + '</table>']; | ||
| for (var i = 0; i < loan.installments.length; i++) { | ||
@@ -42,9 +37,7 @@ var inst = loan.installments[i]; | ||
| } | ||
| html[1] += '<tr>' + '<td>' + trans('sum') + '</td>' + '<td>' + fm(loan.capitalSum) + '</td>' + '<td>' + fm(loan.interestSum) + '</td>' + '<td>' + fm(loan.sum) + '</td>' + '<td>-</td>' + '<td>-</td>' + '</tr>'; | ||
| return html.join(''); | ||
| } | ||
| /* istanbul ignore next */ | ||
| if (typeof module === 'undefined') { | ||
@@ -58,3 +51,2 @@ // browser | ||
| } | ||
| window.LoanJS.loanToHtmlTable = loanToHtmlTable; | ||
@@ -61,0 +53,0 @@ } |
+4
-4
@@ -44,5 +44,5 @@ /* | ||
| return { | ||
| capital: capital, | ||
| interest: interest, | ||
| installment: installment, | ||
| capital, | ||
| interest, | ||
| installment, | ||
| remain: amount - capitalSum - capital, | ||
@@ -95,3 +95,3 @@ interestSum: interestSum + interest | ||
| return { | ||
| installments: installments, | ||
| installments, | ||
| amount: rnd(amount), | ||
@@ -98,0 +98,0 @@ interestSum: rnd(interestSum), |
+9
-9
| { | ||
| "name": "loanjs", | ||
| "version": "1.0.8", | ||
| "version": "1.0.9", | ||
| "main": "LoanJS.js", | ||
@@ -34,11 +34,11 @@ "description": "Calculate loan in js (browser/node.js) for equal installments, installments decreasing, the sum of interest, etc.", | ||
| "devDependencies": { | ||
| "@babel/cli": "^7.17.6", | ||
| "@babel/core": "^7.17.9", | ||
| "@babel/preset-env": "^7.16.11", | ||
| "babel-jest": "^27.5.1", | ||
| "@babel/cli": "^7.22.5", | ||
| "@babel/core": "^7.22.5", | ||
| "@babel/preset-env": "^7.22.5", | ||
| "babel-jest": "^29.5.0", | ||
| "coveralls": "~3.1.1", | ||
| "jest": "~27.5.1", | ||
| "rollup": "~2.70.1", | ||
| "standard": "~16.0.4", | ||
| "uglify-js": "~3.15.4" | ||
| "jest": "~29.5.0", | ||
| "rollup": "~3.25.1", | ||
| "standard": "~17.1.0", | ||
| "uglify-js": "~3.17.4" | ||
| }, | ||
@@ -45,0 +45,0 @@ "scripts": { |
+6
-9
@@ -5,3 +5,2 @@ # LoanJS | ||
| [](http://badge.fury.io/js/loanjs) | ||
| [](https://travis-ci.org/kfiku/LoanJS) [](https://david-dm.org/kfiku/loanjs) | ||
| [](https://coveralls.io/github/kfiku/LoanJS) | ||
@@ -12,7 +11,5 @@  | ||
| [](https://github.com/feross/standard) | ||
| ## Getting Started | ||
| Install the module with: | ||
| Install the module with: | ||
| ``` | ||
@@ -37,3 +34,3 @@ npm install loanjs | ||
| /** returns | ||
| { | ||
| { | ||
| installments : [ | ||
@@ -70,3 +67,3 @@ { | ||
| ```js | ||
| { | ||
| { | ||
| installments : [ | ||
@@ -109,3 +106,3 @@ { | ||
| var loan = new LoanJS.Loan(1000, 12, 5, true); | ||
| var div = document.createElement("div"); | ||
@@ -143,3 +140,3 @@ div.innerHTML = LoanJS.loanToHtmlTable(loan); // loan rendering as html table string | ||
| * update dependencies | ||
| #### 2014-11-10 v0.0.2 | ||
@@ -152,3 +149,3 @@ * now you can use it in node/browserify and browser | ||
| Copyright (c) 2014 Grzegorz Klimek | ||
| Copyright (c) 2014 Grzegorz Klimek | ||
| Licensed under the MIT license. |
26513
-1.87%145
-2.03%