From 8428305c1f9bc07ed84868f64f00625d949afd27 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Wed, 13 Apr 2016 20:18:43 +0100 Subject: [PATCH] Release 1.0.0 --- CHANGELOG.md | 12 ++++++-- dist/{ => src}/index.js | 63 +++++++++++++++++++++-------------------- package.json | 2 +- 3 files changed, 42 insertions(+), 35 deletions(-) rename dist/{ => src}/index.js (63%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 075d9b9..569f72a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,16 @@ # Changelog -## [0.0.2](https://github.com/seegno/ein-validator/tree/0.0.2) (2016-02-17) -[Full Changelog](https://github.com/seegno/ein-validator/compare/0.0.1...0.0.2) +## [v1.0.0](https://github.com/seegno/ein-validator/tree/v1.0.0) (2016-04-13) +[Full Changelog](https://github.com/seegno/ein-validator/compare/v0.0.2...v1.0.0) + +**Merged pull requests:** + +- Update algorithm to accept formatted and non formatted numbers [\#5](https://github.com/seegno/ein-validator/pull/5) ([franciscocardoso](https://github.com/franciscocardoso)) + +## [v0.0.2](https://github.com/seegno/ein-validator/tree/v0.0.2) (2016-02-17) +[Full Changelog](https://github.com/seegno/ein-validator/compare/v0.0.1...v0.0.2) **Merged pull requests:** - Update `es2015-node4` to `es2015` [\#3](https://github.com/seegno/ein-validator/pull/3) ([ruipenso](https://github.com/ruipenso)) -## [0.0.1](https://github.com/seegno/ein-validator/tree/0.0.1) (2016-02-05) diff --git a/dist/index.js b/dist/src/index.js similarity index 63% rename from dist/index.js rename to dist/src/index.js index 712f8d4..7c20ce9 100644 --- a/dist/index.js +++ b/dist/src/index.js @@ -3,14 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = undefined; +exports.isValid = isValid; exports.mask = mask; -var _lodash = require('lodash'); +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } -var _lodash2 = _interopRequireDefault(_lodash); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +/** + * An Employer Identification Number (EIN), also known as a Federal Tax Identification Number, is used to identify a business entity. + * + * NOTES: + * - Prefix 47 is being reserved for future use + * - Prefixes 26, 27, 45, 46 and 47 were previously assigned by the Philadelphia campus. + * + * See `http://www.irs.gov/Businesses/Small-Businesses-&-Self-Employed/How-EINs-are-Assigned-and-Valid-EIN-Prefixes` for more information. + */ /** * Campus prefixes. @@ -30,53 +36,48 @@ var campus = { philadelphia: ['33', '39', '41', '42', '43', '46', '48', '62', '63', '64', '66', '68', '71', '72', '73', '74', '75', '76', '77', '81', '82', '83', '84', '85', '86', '87', '88', '91', '92', '93', '98', '99'], sba: ['31'] }; + /** - * See `http://www.irs.gov/Businesses/Small-Businesses-&-Self-Employed/How-EINs-are-Assigned-and-Valid-EIN-Prefixes` for more information. - * - * An Employer Identification Number (EIN), also known as a Federal Tax Identification Number, is used to identify a business entity. - * - * NOTES: - * - * - Prefix 47 is being reserved for future use - * - Prefixes 26, 27, 45, 46 and 47 were previously assigned by the Philadelphia campus. + * Cache all available prefixes. */ +var prefixes = []; + +for (var location in campus) { + prefixes.push.apply(prefixes, _toConsumableArray(campus[location])); +} + +prefixes.sort(); + /** - * Module dependencies. + * Expression. */ -var prefixes = _lodash2.default.flatten(_lodash2.default.valuesIn(campus)); -var expression = /^(\d{9})$/; +var expression = /^\d{2}[- ]{0,1}\d{7}$/; /** * Validate function. */ -function isValid(ein) { - if (!expression.test(ein)) { +function isValid(value) { + if (!expression.test(value)) { return false; } - return _lodash2.default.includes(prefixes, ein.substr(0, 2)); + return prefixes.indexOf(value.substr(0, 2)) !== -1; } /** - * Masks the EIN with "X" placeholders to protect sensitive data, + * Mask the EIN with "X" placeholders to protect sensitive data, * while keeping some of the original digits for contextual recognition. * - * E.g. "123456789" -> "XXXXX6789" + * E.g. "123456789" -> "XXXXX6789", "12-3456789" -> "XX-XXX6789". */ -function mask(ein) { - if (!isValid(ein)) { +function mask(value) { + if (!isValid(value)) { throw new Error('Invalid Employer Identification Number'); } - return ein.substr(0, ein.length - 4).replace(/[\w]/g, 'X') + ein.substr(-4); -} - -/** - * Export default. - */ - -exports.default = isValid; \ No newline at end of file + return '' + value.substr(0, value.length - 4).replace(/[\w]/g, 'X') + value.substr(-4); +} \ No newline at end of file diff --git a/package.json b/package.json index 6218693..6d6c9a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ein-validator", - "version": "0.0.2", + "version": "1.0.0", "description": "Employer Identification Number validator and masker", "keywords": [ "EIN",