A tiny (~498 bytes) and fast module to calculate loan for JavaScript. May be used in both CommonJS and ES module systems.
Check out live demo.
First, you install it:
$ npm i @apmyp/kredito.js
Then, you just use it like this for annuity payment type:
import { Annuity } from "@apmyp/kredito.js";
const principal = 100000;
const interestRate = 0.12 / 12; // 12% per year we should convert to 1% per month
const installments = 24;
const annuity = new Annuity(principal, interestRate, installments);
annuity.payment(); //=> 4707.35
annuity.percentageInPayment(1); //=> 1000
annuity.bodyInPayment(1); //=> 3707.35
annuity.totalCost(); //=> 112976.33
annuity.overpayment(); //=> 12976.33
Or like this for linear payment type:
import { Linear } from "@apmyp/kredito.js";
const principal = 100000;
const interestRate = 0.12 / 12; // 12% per year we should convert to 1% per month
const installments = 24;
const linear = new Linear(principal, interestRate, installments);
linear.payment(1); //=> 5166.67
linear.percentageInPayment(1); //=> 1000
linear.bodyInPayment(); //=> 4166.67
linear.totalCost(); //=> 112500
linear.overpayment(); //=> 12500
If you want to use CommonJS modules:
const { Annuity, Linear } = require('@apmyp/kredito.js');