calculate-total-cost

1.0.0 • Public • Published

Welcome to calculate-total-cost

Version Documentation Maintenance

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 for unit testing. You can download using below command in your project.

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.

npm install calculate-total-cost

Usage

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.

    //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.

    //getTotal(qty, price_per_item)
    calculate.getTotal(500,1) //Output => 500
  • getDiscountAmount() which takes one arguments: order total and return discount amount .

    //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.

    //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 to see how discount and taxes are calculated.

Run tests

Run below command to run all 17 written test cases.

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

📝 License

Copyright © 2021 Devarsh Patel.
This project is ISC licensed.

Package Sidebar

Install

npm i calculate-total-cost

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

10.5 kB

Total Files

6

Last publish

Collaborators

  • devarsh19