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

calculatetax

v1.0.4

Published

The `calculateTax` function is a utility function designed to calculate tax and total amounts based on input parameters. This function returns a promise that resolves to an object containing the total amount and tax amount.

Downloads

14

Readme

calculateTax Function Documentation

Introduction

The calculateTax function is a utility function designed to calculate tax and total amounts based on input parameters. This function returns a promise that resolves to an object containing the total amount and tax amount.

Function Signature

const calculateTax = (prop1, prop2, profile) => {
    // Function body
}

Parameters

  • prop1: An object that may contain a subTotal property to be used as the base amount.
  • prop2: An object that may contain a tax property to determine the tax rate.
  • profile: An object representing the user's profile information.

Function Logic

  1. The baseAmount is determined based on the provided prop1 object:

    • If prop1.subTotal exists and is not undefined, it is checked whether it is a string. If it is a string, it is converted to a numeric value by removing commas. If it is not a string, it is used as-is. If prop1.subTotal is undefined, the base amount is set to 0.
  2. The tax rate (tax) is determined based on the provided prop2 object and the user's profile:

    • If prop2.tax is 0, the function uses the tax rate from the user's profile (profile.taxType.tax). If prop2.tax is not 0, it is used as the tax rate.
  3. The tax amount is calculated by multiplying the baseAmount by the tax rate and dividing it by 100.

  4. The total amount is calculated by adding the baseAmount and the tax amount.

  5. The function returns a promise that resolves to an object containing:

    • totalAmount: The total amount after applying tax, represented as a float.
    • taxAmount: The tax amount, represented as a float.

Usage Example

import calculateTax from './calculateTax';

// Sample input parameters
const prop1 = { subTotal: '1000,00' }; // Base amount with commas
const prop2 = { tax: 5 }; // Tax rate
const profile = { taxType: { tax: 8 } }; // User's profile

// Calculate tax and total amounts using the calculateTax function
calculateTax(prop1, prop2, profile)
    .then(result => {
        console.log(`Total Amount: $${result.totalAmount.toFixed(2)}`);
        console.log(`Tax Amount: $${result.taxAmount.toFixed(2)}`);
    });

GitHub Repository

Notes

  • This function allows for flexible tax and total amount calculations based on input parameters, providing versatility for different scenarios.

  • It can be used in applications requiring tax calculations for financial transactions.


This Markdown documentation provides a detailed explanation of the calculateTax function, its parameters, and how it performs tax and total amount calculations. It also includes a usage example and a link to the GitHub repository for reference.