Package Exports
- ts-vat
- ts-vat/config.d.ts
- ts-vat/exceptions.d.ts
- ts-vat/index.d.ts
- ts-vat/index.js
- ts-vat/types.d.ts
- ts-vat/vat-calculator.d.ts
Readme

ts-vat
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.
Features
- 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
Installation
npm install ts-vatUsage
Basic VAT Calculation
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) // 100B2B Transactions
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.20VAT Number Validation
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'
// }Special VAT Zones
const calculator = new VatCalculator()
// Calculate VAT for Heligoland (Germany)
const result = calculator.calculate(100, 'DE', 'Heligoland')
console.log(result.vatRate) // 0Configuration
You can configure the calculator with custom options:
const calculator = new VatCalculator({
businessCountryCode: 'DE',
forwardSoapFaults: true,
soapTimeout: 5000, // 5 seconds
rules: {
// Custom VAT rules...
}
})Testing
bun testChangelog
Please see our releases page for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Community
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
Postcardware
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 🌎
Sponsors
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.
Credits
vat-calculatorfor the original PHP implementation- Chris Breuer
- All Contributors
License
The MIT License (MIT). Please see LICENSE for more information.
Made with 💙