# calculate-total-cost

> useful to calculate the total cost of an order including taxes and respected discount

Latest version **1.0.0** (published 2021-02-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install calculate-total-cost
pnpm add calculate-total-cost
yarn add calculate-total-cost
bun add calculate-total-cost
```

## 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.0 |
| Published | 2021-02-03 |
| First published | 2021-02-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Devarsh Patel |
| Maintainers | devarsh19 |
| Keywords | cost, discount, total-cost, sales-tax |

## Links

- npm: https://www.npmjs.com/package/calculate-total-cost
- Repository: https://github.com/speakai/code-exercise
- Homepage: https://github.com/speakai/code-exercise#readme
- Issues: https://github.com/speakai/code-exercise/issues
- npm.io page: https://npm.io/package/calculate-total-cost

## Recent versions

- 1.0.0 (latest) — 2021-02-03

## README

<h1 align="center">Welcome to calculate-total-cost</h1>
<p>
  <img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" />
  <a href="https://github.com/speakai/code-exercise#readme" target="_blank">
    <img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
  </a>
  <a href="https://github.com/speakai/code-exercise/graphs/commit-activity" target="_blank">
    <img alt="Maintenance" src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" />
  </a>
</p>

useful to calculate the total cost of an order including taxes and respected discount based on your order total.

## Dependencies
This package use only one dependency: [mocha](https://www.npmjs.com/package/mocha) for unit testing. You can download using below command in your project.
```sh
npm install --save-dev mocha
```
## Installation
This is a Node.js module available via npm registry. To install and use this module Node.js must be installed on your system. In your projects root directory run below command to install **calculate-total-cost**.

```sh
npm install calculate-total-cost
```

## Usage
```sh
var calculate = require('calculate-total-cost');
```

This package contains 4 methods in total.

- **getTotalCost()** which takes 3 arguments: number of items (number),price per item (number), 2 letter province code (string)
  Return total cost of the order after counting discount (if any) and adding taxes based on respected province. See below code for same. 

    ```sh
    //getTotalCost(qty, price_per_item, province_code)
    calculate.getTotalCost(500,1,"ON") //Output => $565.00
    
    //input: qty: 3600, price_per_item: $2.25, province_code: MI or mi (province code are case insensitive)
    calculate.getTotalCost(3600,2.25,"MI") //Output => $7984.98
    ```

- **getTotal()** which takes two arguments: number of items and price_per_item and return total cose without    disc and tax.
  ```sh
  //getTotal(qty, price_per_item)
  calculate.getTotal(500,1) //Output => 500
  ```
- **getDiscountAmount()** which takes one arguments: order total and return discount amount .
  ```sh
  //getDiscountAmount(qty, price_per_item)
  calculate.getDiscountAmount(500) //Output => 0
  calculate.getDiscountAmount(5000) //Output => 250
  calculate.getDiscountAmount(10000) //Output => 1000
  ```
- **getTaxAmount()** which takes two arguments: order total after discount and 2 letter province code and return tax amount based on given province.
  ```sh
  //getTaxAmount(qty, price_per_item)
  calculate.getTaxAmount(500, "DE") //Output => 0
  calculate.getTaxAmount(500, "ON") //Output => 65
  calculate.getTaxAmount(500, "AB") //Output => 25
  ```  

[Click Here](#list-of-provinces-used) to see how discount and taxes are calculated.

## Run tests
Run below command to run all 17 written test cases. 

```sh
npm test
```

## List of Provinces used
| Province | Tax Rate |
| -------- | -------: |
| AB       |       5% |
| ON       |      13% |
| QC       |  14.975% |
| MI       |       6% |
| DE       |       0% |
## Discount Rate used for Calculation
| Order Value | Discount Rate |
| ----------- | ------------: |
| $1,000      |            3% |
| $5,000      |            5% |
| $7,000      |            7% |
| $10,000     |           10% |

## Author

👤 **Devarsh Patel**

* Github: [@devarsh19](https://github.com/devarsh19)
* LinkedIn: [@devarsh19](https://linkedin.com/in/devarsh19)

## 📝 License

Copyright © 2021 [Devarsh Patel](https://github.com/devarsh19).<br />
This project is [ISC](https://github.com/speakai/code-exercise/blob/master/LICENSE) licensed.

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