- Notifications
You must be signed in to change notification settings - Fork15
Calculate loan in js (browser/node.js) for equal installments, installments decreasing, the sum of interest, etc.
License
NotificationsYou must be signed in to change notification settings
kfiku/LoanJS
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Supersmall andfast module to calculate loan in js (browser/node.js) forequal/decreasing/annuity/annuityDue installments, thesum of interest, etc, with TypeScript support
Install with:
npm install loanjs
import{Loan}from'loanjs';// orconst{ Loan}=require('loanjs');constloan=newLoan(1000,// amount12,// installments number5,// interest rate'annuity'// loanType: 'annuity' | 'annuityDue' | 'diminishing' | GetNextInstalmentPartFunction);/** returns{ installments : [ { capital : number, interest : number, installment : number, remain : number }, //... ], amount : number, interestSum : number, capitalSum : number, sum : number}*/
LoanJS.Loan(amount, installmentsNumber, interestRate, loanType)
Argument | type | default | Description |
---|---|---|---|
amount | number | *required | full amount of Loan |
installmentsNumber | number | *required | how many installments will be (in months) |
interestRate | number | *required | interest rate in percent (ex. 3.5) |
loanType | string or fn | annuity | annuity | annuityDue | diminishing | GetNextInstalmentPartFunction |
interfaceInstallmentPart{capital:number;interest:number;installment:number;}typeGetNextInstalmentPartFunction=(amount:number,installmentsNumber:number,interestRateMonth:number,capitalSum:number)=>InstallmentPart;
{installments :[{capital :number,interest :number,installment :number,remain :number}],amount :number,interestSum :number,capitalSum :number,sum :number}
import{Loan}from'loanjs';constannuityLoan=newLoan(1000,12,5,'annuity');constannuityDueLoan=newLoan(1000,12,5,'annuityDue');constdiminishingLoan=newLoan(1000,12,5,'diminishing');constcustomInstalmentLoan=newLoan(1000,12,5,getNext10Instalment);functiongetNext10Instalment(amount:number,installmentsNumber:number,capitalSum:number,interestRateMonth:number){constcapital=rnd(amount/installmentsNumber);constinterest=10;constinstallment=capital+interest;return{ capital, interest, installment};}
import{Loan}from'loanjs';// orconst{ Loan}=require('loanjs');constloan_1=newLoan(1000,12,5,'diminishing');// loan on 1 000($) in 12 loanType installments (ex. months) with 5% interest rateconstloan_2=newLoan(500000,360,3.5,'annuity');// loan on 500 000($) in 360 equal installments (30 years) with 3.5% interest rate
You can also render loan as html table
<scriptsrc="../../dist/loan.js"></script><scriptsrc="../../dist/loanToHtmlTable.js"></script><script>constloan=newLoanJS.Loan(1000,12,5,'annuity');constdiv=document.createElement("div");div.innerHTML=LoanJS.loanToHtmlTable(loan);// loan rendering as html table stringdocument.body.appendChild(div);</script>
more exampleshere
- InterestJS - counting regular savings
Im open for contributors :).
- add
annuityDue
interest rate loan type - changing the fourth argument
diminishing
toloanType
(annuity
|diminishing
|annuityDue
), with backward compatibility (false == 'annuity', true == 'diminishing') - refactor getNextInstalment to be open for extensions
- add option to provide function to loanType to customize instalments counting
- add TypeScript types
- code cleanup
- packages update
- go to es6
- make dist files
- make 100% covered tests
- update dependencies
- fixing typo intrest -> interest#3
- update dependencies
- update dependencies
- now you can use it in node/browserify and browser
Copyright (c) 2023 Grzegorz KlimekLicensed under the MIT license.
About
Calculate loan in js (browser/node.js) for equal installments, installments decreasing, the sum of interest, etc.
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published