Created
July 2, 2021 17:31
-
-
Save trevorc/08ed199712ab24c1c8ea9a67d760c368 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2020-2021 Trevor Caira | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a | |
* copy of this software and associated documentation files (the "Software"), | |
* to deal in the Software without restriction, including without limitation | |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
* and/or sell copies of the Software, and to permit persons to whom the | |
* Software is furnished to do so, subject to the following conditions: | |
* | |
* The above copyright notice and this permission notice shall be included in | |
* all copies or substantial portions of the Software. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
* THE SOFTWARE. | |
*/ | |
const FEDERAL_BRACKETS = [ | |
[0, .1], | |
[9700, .12], | |
[39475, .22], | |
[84200, .24], | |
[160725, .32], | |
[204100, .35], | |
[510300, .37] | |
]; | |
const STANDARD_DEDUCTION = 12500; | |
const FICA_MAX_INCOME = 142800; | |
const FICA_RATE = 0.062; | |
const MEDICARE_RATE = 0.0145; | |
const MEDICARE_SURTAX_EXEMPTION = 200000; | |
const MEDICARE_SURTAX_RATE = 0.009; | |
const SALT_CAP = 10000; | |
const CO_RATE = 0.0463; | |
const NC_RATE = 0.0525; | |
const PA_RATE = 0.0307; | |
const CA_BRACKETS = [ | |
[0, 0.01], | |
[8809, 0.02], | |
[20883, 0.04], | |
[32960, 0.06], | |
[45753, 0.08], | |
[57824, 0.093], | |
[295373, 0.103], | |
[354445, 0.113], | |
[590742, 0.123], | |
[1000000, 0.133] | |
]; | |
const CT_BRACKETS = [ | |
[0, 0.03], | |
[10000, 0.05], | |
[50000, 0.055], | |
[100000, 0.06], | |
[200000, 0.065], | |
[250000, 0.069], | |
[500000, 0.0699] | |
]; | |
const NJ_BRACKETS = [ | |
[0, 0.014], | |
[20000, 0.0175], | |
[35000, 0.035], | |
[40000, 0.0553], | |
[75000, 0.0637], | |
[500000, 0.0897], | |
[5000000, 0.1075] | |
]; | |
const NYS_BRACKETS = [ | |
[0, .04], | |
[8500, 0.045], | |
[11700, .0525], | |
[13900, 0.059], | |
[21400, 0.0621], | |
[80650, 0.0649], | |
[215400, 0.0685], | |
[1077550, 0.0882] | |
]; | |
const NYC_BRACKETS = [ | |
[0, 0.03078], | |
[12000, 0.03762], | |
[25000, 0.03819], | |
[50000, 0.03876] | |
]; | |
function progressiveIncomeTax(brackets, income) { | |
let tax = 0; | |
for (let i = 0; i < brackets.length - 1; ++i) { | |
const bracketWidth = brackets[i+1][0] - brackets[i][0]; | |
const bracketIncome = Math.min( | |
Math.max(income - brackets[i][0], 0), | |
bracketWidth | |
); | |
tax += brackets[i][1] * bracketIncome; | |
} | |
const [lastThreshold, lastRate] = brackets[brackets.length - 1]; | |
tax += Math.max(0, income - lastThreshold) * lastRate; | |
return tax; | |
} | |
function federalIncomeTax(income) { | |
return progressiveIncomeTax(FEDERAL_BRACKETS, income); | |
} | |
function fica(grossIncome) { | |
return Math.min(grossIncome, FICA_MAX_INCOME) * FICA_RATE; | |
} | |
function medicare(grossIncome) { | |
return grossIncome * MEDICARE_RATE + Math.max(0, grossIncome - MEDICARE_SURTAX_EXEMPTION) * MEDICARE_SURTAX_RATE; | |
} | |
function federalTax(grossIncome, deductions) { | |
return federalIncomeTax(grossIncome - Math.max(deductions, STANDARD_DEDUCTION)) + fica(grossIncome) + medicare(grossIncome); | |
} | |
function flatTax(rate, exemption, income, deductions) { | |
return rate * Math.max(0, income - exemption - deductions); | |
} | |
function stateAndFederalTax(grossIncome, deductions, stateTax) { | |
const itemizedDeductions = Math.min(stateTax, SALT_CAP) + deductions; | |
return stateTax + federalTax(grossIncome, itemizedDeductions); | |
} | |
function coTax(income, deductions) { | |
const stateTax = flatTax(CO_RATE, 0, income, deductions); | |
return stateAndFederalTax(income, deductions, stateTax); | |
} | |
function paTax(income, deductions) { | |
const stateTax = flatTax(0.01 + PA_RATE, 0, income, deductions); | |
return stateAndFederalTax(income, deductions, stateTax); | |
} | |
function paTaxNoLocal(income, deductions) { | |
const stateTax = flatTax(PA_RATE, 0, income, deductions); | |
return stateAndFederalTax(income, deductions, stateTax); | |
} | |
function caTax(income, deductions) { | |
const stateTax = progressiveIncomeTax(CA_BRACKETS, income - deductions); | |
return stateAndFederalTax(income, deductions, stateTax); | |
} | |
function ctTax(income, deductions) { | |
const stateTax = progressiveIncomeTax(CT_BRACKETS, income - deductions); | |
return stateAndFederalTax(income, deductions, stateTax); | |
} | |
function njTax(income, deductions) { | |
const stateTax = progressiveIncomeTax(NJ_BRACKETS, income - deductions); | |
return stateAndFederalTax(income, deductions, stateTax); | |
} | |
function ncTax(income, deductions) { | |
const stateTax = flatTax(NC_RATE, 0, income, deductions); | |
return stateAndFederalTax(income, deductions, stateTax); | |
} | |
function nycTax(income, deductions) { | |
const localTax = progressiveIncomeTax(NYC_BRACKETS, income); | |
const stateTax = progressiveIncomeTax(NYS_BRACKETS, income); | |
return stateAndFederalTax(income, deductions, localTax + stateTax); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment