npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

loanjs

v1.1.2

Published

Calculate loan in js (browser/node.js) for equal installments, installments decreasing, the sum of interest, etc.

Downloads

3,126

Readme

LoanJS

NPM version core gzip size Build status

Super small (~500B) and fast module to calculate loan in js (browser/node.js) for equal/decreasing/annuity/annuityDue installments, the sum of interest, etc, with TypeScript support

Getting Started

Install with:

npm install loanjs

Calculating Loan:

import { Loan } from 'loanjs';
// or
const { Loan } = require('loanjs');

const loan = new Loan(
  1000, // amount
  12,   // installments number
  5,    // 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
}
*/

Documentation

Loan

LoanJS.Loan(amount, installmentsNumber, interestRate, loanType)

Arguments

| 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

interface InstallmentPart {
  capital: number;
  interest: number;
  installment: number;
}

type GetNextInstalmentPartFunction = (
  amount: number,
  installmentsNumber: number,
  interestRateMonth: number,
  capitalSum: number
) => InstallmentPart;

Returns

{
  installments  : [
    {
      capital     : number,
      interest    : number,
      installment : number,
      remain      : number
    }
  ],
  amount        : number,
  interestSum   : number,
  capitalSum    : number,
  sum           : number
}

Examples

typescript example

import { Loan } from 'loanjs';

const annuityLoan = new Loan(1000, 12, 5, 'annuity');

const annuityDueLoan = new Loan(1000, 12, 5, 'annuityDue');

const diminishingLoan = new Loan(1000, 12, 5, 'diminishing');

const customInstalmentLoan = new Loan(1000, 12, 5, getNext10Instalment);
function getNext10Instalment (amount: number, installmentsNumber: number, capitalSum: number, interestRateMonth: number) {
  const capital = rnd(amount / installmentsNumber);
  const interest = 10;
  const installment = capital + interest;

  return { capital, interest, installment };
}

nodejs example

import { Loan } from 'loanjs';
// or
const { Loan } = require('loanjs');

const loan_1 = new Loan(1000, 12, 5, 'diminishing');
// loan on 1 000($) in 12 loanType installments (ex. months) with 5% interest rate

const loan_2 = new Loan(500000, 360, 3.5, 'annuity');
// loan on 500 000($) in 360 equal installments (30 years) with 3.5% interest rate

Browser example:

You can also render loan as html table

<script src="../../dist/loan.js"></script>
<script src="../../dist/loanToHtmlTable.js"></script>
<script>
    const loan = new LoanJS.Loan(1000, 12, 5, 'annuity');

    const div = document.createElement("div");
    div.innerHTML = LoanJS.loanToHtmlTable(loan); // loan rendering as html table string
    document.body.appendChild(div);
</script>

more examples here

Similar projects

Contributing

Im open for contributors :).

Release History

2023-07-25 v1.1.0

  • add annuityDue interest rate loan type
  • changing the fourth argument diminishing to loanType (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

2023-06-23 v1.0.11

  • add TypeScript types
  • code cleanup
  • packages update

2017-08-06 v1.0.0

  • go to es6
  • make dist files
  • make 100% covered tests

2016-02-29 v0.1.4

  • update dependencies

2015-10-12 v0.1.3

  • fixing typo intrest -> interest #3
  • update dependencies

2014-11-10 v0.0.4

  • update dependencies

2014-11-10 v0.0.2

  • now you can use it in node/browserify and browser

License

Copyright (c) 2023 Grzegorz Klimek Licensed under the MIT license.