isVAT.js 797 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isVAT;
  6. exports.vatMatchers = void 0;
  7. var _assertString = _interopRequireDefault(require("./util/assertString"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. var vatMatchers = {
  10. GB: /^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/,
  11. IT: /^(IT)?[0-9]{11}$/,
  12. NL: /^(NL)?[0-9]{9}B[0-9]{2}$/
  13. };
  14. exports.vatMatchers = vatMatchers;
  15. function isVAT(str, countryCode) {
  16. (0, _assertString.default)(str);
  17. (0, _assertString.default)(countryCode);
  18. if (countryCode in vatMatchers) {
  19. return vatMatchers[countryCode].test(str);
  20. }
  21. throw new Error("Invalid country code: '".concat(countryCode, "'"));
  22. }