A TypeScript VAT calculator for EU countries. This package helps you calculate VAT rates for different EU countries, validate VAT numbers, and handle special VAT rules and exceptions.
- Calculate VAT for all EU countries
- Support for different VAT rates (standard, reduced, super-reduced)
- VAT number validation through VIES
- Special VAT zones and exceptions handling
- B2B and B2C VAT calculations
- TypeScript support with full type safety
npm install ts-vat
import { VatCalculator } from 'ts-vat'
const calculator = new VatCalculator()
// Calculate VAT for a net price
const result = calculator.calculate(100, 'DE') // Germany
console.log(result)
// {
// netPrice: 100,
// grossPrice: 119,
// vatAmount: 19,
// vatRate: 0.19,
// countryCode: 'DE',
// isCompany: false
// }
// Calculate net price from gross price
const netResult = calculator.calculateNet(119, 'DE')
console.log(netResult.netPrice) // 100
const calculator = new VatCalculator({
businessCountryCode: 'DE'
})
// B2B transaction within same country
const result = calculator.calculate(100, 'DE', undefined, true)
console.log(result.vatRate) // 0
// B2B transaction with different country
const result2 = calculator.calculate(100, 'FR', undefined, true)
console.log(result2.vatRate) // 0.20
const calculator = new VatCalculator()
// Check if VAT number is valid
const isValid = await calculator.isValidVatNumber('DE123456789')
console.log(isValid)
// Get detailed VAT number information
const details = await calculator.getVatDetails('DE123456789')
console.log(details)
// {
// isValid: true,
// name: 'Company Name',
// address: 'Company Address',
// countryCode: 'DE',
// vatNumber: '123456789'
// }
const calculator = new VatCalculator()
// Calculate VAT for Heligoland (Germany)
const result = calculator.calculate(100, 'DE', 'Heligoland')
console.log(result.vatRate) // 0
You can configure the calculator with custom options:
const calculator = new VatCalculator({
businessCountryCode: 'DE',
forwardSoapFaults: true,
soapTimeout: 5000, // 5 seconds
rules: {
// Custom VAT rules...
}
})
bun test
Please see our releases page for more information on what has changed recently.
Please see CONTRIBUTING for details.
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
For casual chit-chat with others using this package:
Join the Stacks Discord Server
Stacks OSS will always stay open-sourced, and we will always love to receive postcards from wherever Stacks is used! And we also publish them on our website. Thank you, Spatie.
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States π
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
vat-calculator
for the original PHP implementation- Chris Breuer
- All Contributors
The MIT License (MIT). Please see LICENSE for more information.
Made with π