validate-vat
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -1,5 +0,5 @@ | ||
// Generated by CoffeeScript 1.6.3 | ||
// Generated by CoffeeScript 1.12.2 | ||
(function() { | ||
var ERROR_MSG, EU_COUNTRIES_CODES, exports, getReadableErrorMsg, headers, http, parseSoapResponse, parsedUrl, serviceUrl, soapBodyTemplate, url, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
@@ -21,4 +21,4 @@ url = require('url'); | ||
'SERVICE_UNAVAILABLE': 'The VIES VAT service is unavailable, please try again later', | ||
'MS_UNAVAILABLE': 'The VAT database of the reqeust member country is unavailable, please try again later', | ||
'TIMEOUT': 'The request to VAT database of the reqeust member country is time out, please try again later', | ||
'MS_UNAVAILABLE': 'The VAT database of the requested member country is unavailable, please try again later', | ||
'TIMEOUT': 'The request to VAT database of the requested member country has timed out, please try again later', | ||
'SERVER_BUSY': 'The service cannot process your request, please try again later', | ||
@@ -79,5 +79,9 @@ 'UNKNOWN': 'Unknown error' | ||
module.exports = exports = function(countryCode, vatNumber, callback) { | ||
module.exports = exports = function(countryCode, vatNumber, timeout, callback) { | ||
var options, req, xml; | ||
if (__indexOf.call(EU_COUNTRIES_CODES, countryCode) < 0 || !(vatNumber != null ? vatNumber.length : void 0)) { | ||
if (typeof timeout === 'function') { | ||
callback = timeout; | ||
timeout = null; | ||
} | ||
if (indexOf.call(EU_COUNTRIES_CODES, countryCode) < 0 || !(vatNumber != null ? vatNumber.length : void 0)) { | ||
return process.nextTick(function() { | ||
@@ -103,10 +107,10 @@ return callback(new Error(ERROR_MSG['INVALID_INPUT'])); | ||
return res.on('end', function() { | ||
var data, err, _ref; | ||
var data, err, ref; | ||
try { | ||
data = parseSoapResponse(str); | ||
} catch (_error) { | ||
err = _error; | ||
} catch (error) { | ||
err = error; | ||
return callback(err); | ||
} | ||
if ((_ref = data.faultString) != null ? _ref.length : void 0) { | ||
if ((ref = data.faultString) != null ? ref.length : void 0) { | ||
err = new Error(getReadableErrorMsg(data.faultString)); | ||
@@ -119,2 +123,7 @@ err.code = data.faultCode; | ||
}); | ||
if (timeout) { | ||
req.setTimeout(timeout, function() { | ||
return req.abort(); | ||
}); | ||
} | ||
req.on('error', callback); | ||
@@ -121,0 +130,0 @@ req.write(xml); |
{ | ||
"name": "validate-vat", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "A Europe VAT number validation lib", | ||
"main": "lib/index.js", | ||
"dependencies": { | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"coffee-script": "~1.6.3", | ||
"mocha": "~1.14.0", | ||
"coffee-script": "~1.12.2", | ||
"mocha": "~3.2.0", | ||
"expect.js": ">=0.2.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha --compilers coffee:coffee-script -R spec -t 10000 --recursive test", | ||
"test": "mocha --compilers coffee:coffee-script/register -R spec -t 10000 --recursive test", | ||
"prepublish": "coffee --output lib --compile src" | ||
@@ -30,3 +29,3 @@ }, | ||
"author": "Bill Gao", | ||
"license": "BSD-2-Clause", | ||
"license": "MIT", | ||
"bugs": { | ||
@@ -33,0 +32,0 @@ "url": "https://github.com/viruschidai/validate-vat/issues" |
# Validate European VAT number | ||
[![Build Status](https://travis-ci.org/viruschidai/validate-vat.png?branch=master)](https://travis-ci.org/viruschidai/validate-vat) | ||
[![Downloads](https://img.shields.io/npm/dm/validate-vat.svg)](https://www.npmjs.com/package/validate-vat) | ||
You can verify the validity of a VAT number issued by any European Union Member State by by using this library. This lib is basically calling web service provided by VIES (at http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl) for VAT number validation. | ||
@@ -50,8 +53,8 @@ | ||
```javascript | ||
'The provided CountryCode is invalid or the VAT number is empty', | ||
'The VIES VAT service is unavailable, please try again later', | ||
'The VAT database of the reqeust member country is unavailable, please try again later', | ||
'The request to VAT database of the reqeust member country is time out, please try again later', | ||
'The service cannot process your request, please try again later', | ||
'Unknown error' | ||
'The provided CountryCode is invalid or the VAT number is empty' | ||
'The VIES VAT service is unavailable, please try again later' | ||
'The VAT database of the requested member country is unavailable, please try again later' | ||
'The request to VAT database of the requested member country has timed out, please try again later' | ||
'The service cannot process your request, please try again later' | ||
'Unknown error' | ||
``` | ||
@@ -58,0 +61,0 @@ For more details usage, please check test |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
120
95
9428
5