Skip to content

Commit

Permalink
update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
gltgrzegorz committed Jun 22, 2023
1 parent 1d522f5 commit 36870bf
Show file tree
Hide file tree
Showing 6 changed files with 6,023 additions and 10,020 deletions.
23 changes: 5 additions & 18 deletions dist/loan.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"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';

/*
* LoanJS
* Calculating loan in equal or diminishing installments
Expand All @@ -19,10 +19,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
*
* @returns {number}
*/

function rnd(num) {
return Math.round(num * 100) / 100;
}

/*
* LoanJS
* Calculating loan in equal or diminishing installments
Expand All @@ -43,15 +43,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
*
* @returns {{ capital: number, interest: number, installment: number, remain: number, interestSum: number }}
*/


var getNextInstalment = function getNextInstalment(amount, installmentsNumber, interestRate, diminishing, capitalSum, interestSum) {
var capital;
var interest;
var installment;
var irmPow;
var interestRateMonth = interestRate / 1200;

if (diminishing) {
capital = rnd(amount / installmentsNumber);
interest = rnd((amount - capitalSum) * interestRateMonth);
Expand All @@ -62,7 +59,6 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
interest = rnd((amount - capitalSum) * interestRateMonth);
capital = installment - interest;
}

return {
capital: capital,
interest: interest,
Expand All @@ -71,6 +67,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
interestSum: interestSum + interest
};
};

/**
* Create Loan Object with all installments and sum of interest
*
Expand All @@ -81,37 +78,29 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
*
* @return {object}
*/


function Loan(amount, installmentsNumber, interestRate) {
var diminishing = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;

/** Checking params */
if (!amount || amount <= 0 || !installmentsNumber || installmentsNumber <= 0 || !interestRate || interestRate <= 0) {
throw new Error("wrong parameters: ".concat(amount, " ").concat(installmentsNumber, " ").concat(interestRate));
}

var installments = [];
var interestSum = 0;
var capitalSum = 0;
var sum = 0;

for (var i = 0; i < installmentsNumber; i++) {
var inst = getNextInstalment(amount, installmentsNumber, interestRate, diminishing, capitalSum, interestSum);
sum += inst.installment;
capitalSum += inst.capital;
interestSum += inst.interest;
/** adding lost sum on rounding */

if (i === installmentsNumber - 1) {
capitalSum += inst.remain;
sum += inst.remain;
inst.remain = 0;
}

installments.push(inst);
}

return {
installments: installments,
amount: rnd(amount),
Expand All @@ -120,9 +109,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
sum: rnd(sum)
};
}
/* istanbul ignore next */


/* istanbul ignore next */
if (typeof module === 'undefined') {
// browser
if ((typeof LOANJS_NAMESPACE === "undefined" ? "undefined" : _typeof(LOANJS_NAMESPACE)) === 'object') {
Expand All @@ -131,7 +119,6 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
if (!window.LoanJS) {
window.LoanJS = {};
}

window.LoanJS.Loan = Loan;
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion dist/loan.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 5 additions & 13 deletions dist/loanToHtmlTable.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,42 @@
"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';

/**
* Create Loan Object with all installments and sum of interest
* @param {Loan} loan loan object
* @param {object} params params
*
* @return {string} html string with table
*/

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) {
if (params.translations && params.translations[key]) {
return params.translations[key];
} else {
return 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++) {
var inst = loan.installments[i];
var instHtml = '<tr>' + '<td>' + (i + 1) + '</td>' + '<td>' + fm(inst.capital) + '</td>' + '<td>' + fm(inst.interest) + '</td>' + '<td>' + fm(inst.installment) + '</td>' + '<td>' + fm(inst.remain) + '</td>' + '<td>' + fm(inst.interestSum) + '</td>' + '</tr>';
html[1] += instHtml;
}

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 */


/* istanbul ignore next */
if (typeof module === 'undefined') {
// browser
if ((typeof LOANJS_NAMESPACE === "undefined" ? "undefined" : _typeof(LOANJS_NAMESPACE)) === 'object') {
Expand All @@ -52,7 +45,6 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
if (!window.LoanJS) {
window.LoanJS = {};
}

window.LoanJS.loanToHtmlTable = loanToHtmlTable;
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions lib/loan.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const getNextInstalment = (
}

return {
capital: capital,
interest: interest,
installment: installment,
capital,
interest,
installment,
remain: amount - capitalSum - capital,
interestSum: interestSum + interest
}
Expand Down Expand Up @@ -91,7 +91,7 @@ function Loan (amount, installmentsNumber, interestRate, diminishing = false) {
}

return {
installments: installments,
installments,
amount: rnd(amount),
interestSum: rnd(interestSum),
capitalSum: rnd(capitalSum),
Expand Down
Loading

0 comments on commit 36870bf

Please sign in to comment.