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

installment-js

v1.1.1

Published

a library help to calculate installment/loan

Downloads

24

Readme

Installment JS

a fast module to calculate loan/installment in js (browser/node.js) for Outstanding debt gradually decreases or Principal and interest divided equally installments, the sum of interest, detail of payment period, etc

Getting Started

Install with:

npm install installment-js

Calculating Installment:

  const { calculateInstallment } = require("installment-js");

  const result = calculateInstallment(
    500000000, //amount
    60, // total of months Installment
    7, // annual interest rate
    [installmentType?], //(optional) installment type InstallmentType.ODGE for Outstanding debt gradually decreases and InstallmentType.PIDE for Principal and interest divided equally
    [rounding?] // (optional) rounding for amount, you can pass the number or use the constant Rounding.ZERO, Rounding.ONE, Rounding.TWO,...
  );

/*
  returns
  {
    loanAmount: 500000000,
    totalLoanAndInterest: 588953250,
    totalInterest: 88953250,
    details: [
      {
        loanBeginingPeriod: 500000000,
        originLoanPaid: 6899388,
        interest: 2916500,
        totalPaid: 9815888,
        loanEndingPeriod: 493100612,
        month: 1
      },
      {
        loanBeginingPeriod: 493100612,
        originLoanPaid: 6947996,
        interest: 2867892,
        totalPaid: 9815888,
        loanEndingPeriod: 486152616,
        month: 2
      },
      ...
    ]
  }
*/

Documentation

Installment

calculateInstallment(amount, months, rate, [installmentType?], [rounding?])

Arguments

| Argument | type | default | Description | | --------------- | ---------------------- | -------------------- | ----------------------------------------- | | amount | number | *required | full amount of Loan | | months | number | *required | how many installments will be (in months) | | rate | number | *required | annual interest rate in percent (ex. 3.5) | | installmentType | InstallmentType | InstallmentType.ODGD | kind of Installment | | rounding | number or Rounding | Rounding.ZERO | Rounding for the money |

InstallmentType Constant

| Constant | Value | Description | | -------- | ----- | -------------------------------------- | | ODGD | 0 | Outstanding debt gradually decreases | | PIDE | 1 | Principal and interest divided equally |

  • Outstanding debt gradually decreases(ODGD) image

  • Principal and interest divided equally (PIDE) image

Rounding Constant

| Constant | Value | Description | | -------- | ----- | -------------------------------------------------- | | ZERO | 0 | No Rounding | | ONE | 1 | Round to 1 decimal places (5.123 -> 5.1) | | TWO | 2 | Round to 2 decimal places (5.123 -> 5.12) | | THREE | 3 | Round to 3 decimal places (5.123 -> 5.123) |

Returns

{
  loanAmount: 500000000,
  totalLoanAndInterest: 588953250,
  totalInterest: 88953250,
  details: [
    {
      loanBeginingPeriod: 500000000,
      originLoanPaid: 6899388,
      interest: 2916500,
      totalPaid: 9815888,
      loanEndingPeriod: 493100612,
      month: 1
    },
    {
      loanBeginingPeriod: 493100612,
      originLoanPaid: 6947996,
      interest: 2867892,
      totalPaid: 9815888,
      loanEndingPeriod: 486152616,
      month: 2
    },
    {
      loanBeginingPeriod: 486152616,
      originLoanPaid: 6996605,
      interest: 2819283,
      totalPaid: 9815888,
      loanEndingPeriod: 479156011,
      month: 3
    },
    ...
  ]
}

Examples

import {
  calculateInstallment,
  InstallmentType,
  Rounding,
} from "installment-js";

const result = calculateInstallment(500, 12, 7.5);

const result1 = calculateInstallment(500, 12, 7.5, InstallmentType.PIDE);

const result1 = calculateInstallment(
  500,
  12,
  7.5,
  InstallmentType.PIDE,
  Rounding.TWO
);

Contributing

Im open for contributors :).

Release History

2024-03-04 v1.1.0

  • Updated the formula for Principal and interest divided equally. The formula for calculating the monthly payment for a loan in the annuity method is as follows:

    PMT = (P * r * (1 + r)^n) / ((1 + r)^n - 1)

    Where:

    • PMT is the monthly payment.
    • P is the initial loan amount (principal).
    • r is the monthly interest rate (usually expressed as a decimal and calculated by dividing the annual interest rate by 12).
    • n is the total number of payment periods (months).