protaxer
v0.2.0
Published
A package for calculating tax based on a specified rate, designed for use with ProBot.
Downloads
19
Maintainers
Readme
ProTaxer
ProTaxer is a simple npm package for calculating tax based on a specified rate. It is designed for use with ProBot or any other project needing tax calculations.
Features
- Calculate Tax: Determine the amount of tax based on a given value.
- Taxed Value: Get the total value including tax.
- Without Tax: Get the original value before tax was applied.
- Custom Tax Rate: Set a custom tax rate with a default of 20%.
- Floating Point Precision: Optionally handle calculations with floating point precision.
- Discounts: Apply discounts to the initial value before tax calculation.
- Currency Formatting: Convert values to currency strings.
- History Tracking: Track historical calculations.
Installation
To install ProTaxer, run:
npm install protaxer
Usage
Basic Usage
import { Taxer } from 'protaxer';
// Create an instance of Taxer with a value
const taxer = new Taxer(100); // Default tax rate is 20%
console.log(`Tax: ${taxer.Tax}`); // Calculate tax
console.log(`Taxed Value: ${taxer.TaxedValue}`); // Calculate value including tax
console.log(`Without Tax: ${taxer.WithoutTax}`); // Calculate value without tax
Custom Tax Rate and Precision
import { Taxer } from 'protaxer';
// Create an instance with a custom tax rate and floating point precision
const taxer = new Taxer(100, 25, true); // Custom tax rate of 25% and float precision
console.log(`Tax: ${taxer.Tax}`); // Calculate tax
console.log(`Taxed Value: ${taxer.TaxedValue}`); // Calculate value including tax
console.log(`Without Tax: ${taxer.WithoutTax}`); // Calculate value without tax
API
Taxer
Constructor(value: number, TAX_RATE?: number, float?: boolean)
value
: The initial value for tax calculations.TAX_RATE
: The tax rate to apply (default: 20%).float
: Whether to return results as floats (default: false).
get Tax()
- Returns the tax amount.
get TaxedValue()
- Returns the value including tax.
get WithoutTax()
- Returns the value without tax.
get NonTax()
- Returns the value excluding tax.
get InclusiveTax()
- Returns the tax amount from an already taxed value.
get ExclusiveTaxedValue()
- Returns the total value including tax from an already taxed value.
set Rate(rate: number)
- Sets a custom tax rate.
set Float(float: boolean)
- Sets whether results should be returned as floats.
Discount(discount: number): number
- Applies a discount to the initial value before tax calculation.
ToJSON()
- Serializes the instance to a JSON string.
ToString()
- Returns a string representation of the instance.
FromJSON(json: string): Taxer
- Creates an instance from a JSON string.
ToCurrencyString(locale: string = 'en-US', currency: string = 'USD'): string
- Converts the value to a currency string.
SaveToHistory()
- Saves the current calculation to history.
FetchHistory()
- Retrieves the history of calculations.
ResetHistory()
- Clears the history of calculations.
ResetRate()
- Resets the tax rate to the default (20%).
ValueString()
- Returns the value as a formatted string.
UnShorthand(float: boolean = true): string
- Converts a shorthand notation to a full numeric value.
Print()
- Prints a table of tax-related information to the console.
ProBot
Constructor(client: Client)
client
: An instance of the Discord.js Client.
On(event: string, handler: (data: Data) => void): void
- Registers a handler for a specific event.
AddUserId(userId: string): void
- Adds a user ID to the filter list.
RemoveUserId(userId: string): void
- Removes a user ID from the filter list.
ClearFilter(): void
- Clears all user IDs from the filter list.
GetLast(): any
- Retrieves the latest income data.
SetNotification(channelId: string, message: string): void
- Sets up the notification details.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
If you would like to contribute to ProTaxer, please fork the repository and submit a pull request with your changes. Contributions are always welcome!
Questions?
For questions or issues, please open an issue on the GitHub repository.