# basicinterest

> interest calculator

Latest version **1.0.1** (published 2021-01-24) · AGPLv3 license · 0 weekly downloads

## Install

```sh
npm install basicinterest
pnpm add basicinterest
yarn add basicinterest
bun add basicinterest
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-01-24 |
| First published | 2021-01-24 |
| Weekly downloads | 0 |
| License | AGPLv3 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | illemoji |
| Maintainers | illemoji |

## Links

- npm: https://www.npmjs.com/package/basicinterest
- npm.io page: https://npm.io/package/basicinterest

## Recent versions

- 1.0.1 (latest) — 2021-01-24
- 1.0.0 — 2021-01-24

## README

# Install

> npm install basicinterest

# Methods

## interest()

Calculates the *unaccumulated* interest `percentage` on an `amount` using the interest rated provided, from `from` to `to`.

Usage:
> interest (amount, percentage, from, to)

Takes the following parameters:
- `amount` is the base amount to calculate the interest for.
- `percentage` is the *yearly* interest rate in %.
- `from` is the starting date in yyyy-mm-dd format for the calculation.
- `to` is the ending date in yyyy-mm-dd format for the calculation.

Returns an `int` or `float` on success, or `false` on error.

Example:

    > interest(100, 25, '2020-05-01', '2022-01-01')
    141.78082191780823


## accinterest()

Calculates the *accumulated* interest `percentage` on an `amount` using the interest rated provided, from `from` to `to`.
Note that interest accumulation is performed every cycle of 365 days (not necessarily calendar year).

Usage:
> accinterest (amount, percentage, from, to)

Takes the following parameters:
- `amount` is the base amount to calculate the interest for.
- `percentage` is the *yearly* interest rate in %.
- `from` is the starting date in yyyy-mm-dd format for the calculation.
- `to` is the ending date in yyyy-mm-dd format for the calculation.

Returns an `int` or `float` on success, or `false` on error.

Example:

    > accinterest(100, 25, '2020-05-01', '2022-01-01')
    145.97602739726028

## howlong()

Calculates the amount of time it'll take `amount` to become `goal` at a yearly *unaccumulated* interest of `percentage`.

Usage:
> howlong (amount, percentage, goal, returnyears)

Takes the following parameters:
- `amount` is the base amount to calculate the interest for.
- `percentage` is the *yearly* interest rate in %.
- `goal` is the goal to reach.
- `returnyears` is an *optional* boolean defining whether to return *years* instead of *days*.


Returns an `int` (days) or `float` (years) on success, or `false` on error.

Example:

    > howlong(100, 25, 200, false)
    1134
    > howlong(100, 25, 200, true)
    3.10628371950539

## howmuchinterest()

Calculates the *unaccumulated* interest required for `amount` to become `goal`, within the time period of `from` and `to`.

Usage:
> howmuchinterest (amount, goal, from, to)

Takes the following parameters:
- `amount` is the base amount to calculate the interest for.
- `goal` is the goal to reach.
- `from` is the starting date in yyyy-mm-dd format for the calculation.
- `to` is the ending date in yyyy-mm-dd format for the calculation.

Returns an `int` (days) or `float` (years) on success, or `false` on error.

Example:

    > howmuchinterest(100, 200, '2020-05-01', '2022-01-01')
    1.5139952255590707

## tests()

Runs all functions with predefined arguments to make sure the code works as expected (manual unit testing :D).
The output below is expected to be the same every time.

The output of `tests()` should be as such:
```
141.78082191780823
145.97602739726028
3.10628371950539 years
1134 days
1.5139952255590707
```

# Known culprits

1. Only common sense sanity checks are performed on the input. Non-existing dates that would synthetically make sense are accepted, e.g. `2020-02-30`, but aren't handled.

# Disclaimer

This is a school project. You shouldn't rely on this package or the output of its methods for anything of importance.

# License
AGPLv3.

---
_Source: https://npm.io/package/basicinterest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
