Comparing version 1.0.5 to 1.1.0
@@ -18,2 +18,6 @@ /* | ||
var validate_eu_vat = require("validate-vat"); | ||
var validate_us_vat = require("ein-validator"); | ||
var regex_ca_vat = /^[0-9]{9}$/; | ||
var tax_rates = require("../res/sales_tax_rates.json"); | ||
@@ -36,3 +40,3 @@ | ||
* @param {string} countryCode | ||
* @return {boolean} Whether country has any sales tax | ||
* @return {boolean} Whether country has sales tax | ||
*/ | ||
@@ -53,3 +57,3 @@ SalesTax.prototype.hasSalesTax = function( | ||
* @param {string} stateCode | ||
* @return {boolean} Whether country state has any sales tax | ||
* @return {boolean} Whether country state has sales tax | ||
*/ | ||
@@ -156,2 +160,18 @@ SalesTax.prototype.hasStateSalesTax = function( | ||
switch (countryCode) { | ||
// United States | ||
case "US": { | ||
// Validate US EIN | ||
return __Promise.resolve( | ||
validate_us_vat.isValid(taxNumber) && true | ||
); | ||
} | ||
// Canada | ||
case "CA": { | ||
// Validate CA BN | ||
return __Promise.resolve( | ||
regex_ca_vat.test(taxNumber) && true | ||
); | ||
} | ||
// Europe member states | ||
@@ -158,0 +178,0 @@ case "AT": |
{ | ||
"name": "sales-tax", | ||
"description": "International sales tax calculator for Node (offline, except for VAT number validation). Tax rates are kept up-to-date.", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/valeriansaliou/node-sales-tax", | ||
@@ -43,2 +43,3 @@ "license": "MIT", | ||
"validate-vat": "0.5.0", | ||
"ein-validator": "1.0.0", | ||
"es6-promise-polyfill": "1.2.0" | ||
@@ -45,0 +46,0 @@ }, |
@@ -65,3 +65,3 @@ # node-sales-tax | ||
:us: **Check some United States states for sales tax** (returns `true` or `false`): | ||
:us: **Check some US states for sales tax** (returns `true` or `false`): | ||
@@ -163,3 +163,3 @@ ```javascript | ||
:estonia: **Given an Estonian customer without any VAT number, buying for 100.00€ of goods** (eg. a physical person): | ||
:estonia: **Given an Estonian customer without any VAT number, buying 100.00€ of goods** (eg. a physical person): | ||
@@ -244,3 +244,3 @@ ```javascript | ||
:morocco: **Given an United States > Delaware-based customer**: | ||
:us: **Given an United States > Delaware-based customer**: | ||
@@ -283,5 +283,5 @@ ```javascript | ||
**It is kept up-to-date with the year-by-year tax changes worldwide.** | ||
**It is kept up-to-date year-by-year with tax changes worldwide.** | ||
Some countries have multiple sales tax, eg. Brazil. In those cases, the returned sales tax is the one on services. Indeed, I consider most users of this module use it for their SaaS business — in other words, service businesses. | ||
Some countries have multiple sales tax, eg. Brazil. In those cases, the returned sales tax is the one on services. Indeed, I consider most users of this module use it for their SaaS business — _in other words, service businesses._ | ||
@@ -292,3 +292,3 @@ ## How are tax numbers validated? | ||
### :eu: European countries | ||
### :eu: Europe | ||
@@ -298,1 +298,15 @@ European VAT numbers are validated against the official `ec.europa.eu` API, which return whether a given VAT number exists or not. This helps you ensure a customer-provided VAT number is valid (ie. you don't have to bill VAT for this customer). | ||
You can manually check a VAT number on [VIES VAT number validation](http://ec.europa.eu/taxation_customs/vies/vatRequest.html). | ||
### :us: United States | ||
United States EIN (U.S. Employer Identification Number) are validated against EIN format rules. | ||
### :canada: Canada | ||
Canada BN (Business Number) are validated against BN format rules. | ||
### :black_flag: Rest of the world | ||
If a country or economic community is not listed here, provided tax identification numbers are ignored for those countries (considered as invalid — so do not rely on validation methods as a source of truth). | ||
_If you need tax number validation for a missing country, feel free to submit a Pull Request._ |
29877
957
307
3
+ Addedein-validator@1.0.0
+ Addedein-validator@1.0.0(transitive)