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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@arraypress/tax-calculator

v1.0.0

Published

Pure tax computation for ecommerce — exclusive/inclusive modes, per-line distribution with rounding, product type filtering. All amounts in cents.

Downloads

70

Readme

@arraypress/tax-calculator

Pure tax computation for ecommerce. Exclusive and inclusive tax modes, per-line distribution with exact rounding, product type filtering, and jurisdiction matching. All amounts in cents.

Installation

npm install @arraypress/tax-calculator

Quick Start

import { computeTax, matchTaxRate } from '@arraypress/tax-calculator';

// Find the best matching rate for the customer's location
const rate = matchTaxRate(taxRates, 'US', 'CA');

// Compute tax
const result = computeTax({
  lineItems: [
    { unitAmount: 5000, quantity: 1, productType: 'physical' },
    { unitAmount: 3000, quantity: 2, productType: 'digital' },
  ],
  rate: { rate: 8.25, taxType: 'exclusive', appliesTo: 'all' },
});
// result.taxAmount === 907 (8.25% of 11000)
// result.lineItems — each has taxAmount and taxRate stamped

API

computeTax({ lineItems, rate })

Compute tax for a set of line items given a rate. Pure function — does not mutate input.

Tax modes:

  • exclusive — tax is added on top. taxAmount is the extra charge.
  • inclusive — tax is in the price. taxAmount is 0, but inclusiveTaxAmount reports what's embedded.

Product type filtering via rate.appliesTo:

  • 'all' — every line is taxable
  • 'physical' — only productType === 'physical' lines
  • 'digital' — only non-physical lines

Per-line exemptions: Set taxExempt: true on any line item to exclude it from tax regardless of product type or appliesTo. Use for tax-exempt customers, reseller certificates, or individual product overrides.

computeTax({
  lineItems: [
    { unitAmount: 5000, quantity: 1, productType: 'physical' },
    { unitAmount: 3000, quantity: 1, productType: 'physical', taxExempt: true },
  ],
  rate: { rate: 10, taxType: 'exclusive', appliesTo: 'all' },
});
// taxableAmount: 5000 (exempt line excluded)
// taxAmount: 500

Returns TaxResult:

  • taxAmount — tax to add (0 for inclusive)
  • inclusiveTaxAmount — tax embedded in price (0 for exclusive)
  • taxableAmount — sum of taxable line item amounts
  • lineItems — cloned items with taxAmount and taxRate set

Rounding: Order-level tax is computed first, then distributed by revenue share. The last taxable line absorbs any remainder so per-line sum always equals the order total exactly.

matchTaxRate(rates, country, state?)

Find the most specific matching tax rate from a list.

Priority:

  1. Exact country + state match
  2. Country-only match (state is null on the rate)
  3. Default rate (country is null)

Only enabled rates are considered. Returns null if no match. Case-insensitive.

Tax Modes

Exclusive (US-style): Prices are pre-tax. Tax is calculated and added at checkout.

Subtotal: $100.00 + Tax: $8.25 = Total: $108.25

Inclusive (EU/UK-style): Prices already include tax. The tax amount is extracted for receipt purposes but nothing is added to the total.

Price: £120.00 (includes £20.00 VAT) = Total: £120.00

License

MIT