Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
tax-brackets
Advanced tools
Easily calculate tax brackets and total payable for progressive taxation systems
Easily calculate tax brackets and total payable for progressive taxation systems
tax-brackets is a small module working in both Node and the browser that lets you calculate taxes for a progressive taxation system. Such systems do not simply apply a fixed percentage to the complete amount but will split it up in so called brackets. Each of these brackets - at least one - is then taxed at a different, increasing rate.
A bracket is defined by a percentage and the lowest and highest taxable amount at that rate.
Two functions are available:
calculate
take an amount and a set of brackets and return the total amount payableget
will take this same input and show exactly how the amount is split up and what the individual amounts are taxed at. This would work well if you not only want to show the total payable but also explain how it was calculated.const taxBrackets = require('tax-brackets')
/*
Both functions expect the rates to be passed as an array of arrays.
Each element is composed as such: [lowestAmount, highestAmount, rate (in percentage)]
*/
const rates = [[1, 50000, 5], [50001, 100000, 10], [100001, Infinity, 15] // Note the need to use Infinity in the last item
/*
This will itself return an array with each element composed as such: [amount taxable, rate applied]
In the example below, the result will be [[50000, 5], [25000, 10]]. You could render that to e.g a table
*/
const brackets = taxBrackets.get(75000, rates)
/*
Using the same amount and rates, the total payable becomes (50000 * 0.05) + (25000 * 0.10) or 5000
*/
const tax = taxBrackets.calculate(75000, rates)
Most of this code will be the same. You should however load tax-brackets from the tax-brackets.js
file after which both functions will be available under the global variable taxBrackets
. The (simplified) code thus becomes:
<script src="tax-brackets.js"></script>
<script>
const rates = [[1, 50000, 5], [50001, 100000, 10], [100001, Infinity, 15]
const brackets = taxBrackets.get(75000, rates)
const tax = taxBrackets.calculate(75000, rates)
</script>
As of right now, this module is mostly the answer to me noticing I was writing the same (sloppy) code over and over again. In other words: it scratches my itch but might not do so for you.
That means for instance no checking is done on the rates you provide. You should particularly be careful to not have the amounts overlap and avoid missing ranges. Providing rates like [[1, 25000, 2], [25000, 35000, 4], [40000, Infinity]]
will get you in trouble. It also explains the need to go up to Infinity (but not beyond) on the last element in the array.
Finally, please note that the amount returned by the calculate
function will always be rounded to the nearest integer. That's somewhat of an arbitrary choice and might change in the (near future).
MIT (c) 2018 Raphael Cockx (@raphaelcockx)
FAQs
Easily calculate tax brackets and total payable for progressive taxation systems
The npm package tax-brackets receives a total of 0 weekly downloads. As such, tax-brackets popularity was classified as not popular.
We found that tax-brackets demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.