Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui Marinho committed Apr 13, 2016
1 parent e9841c3 commit 8428305
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 35 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
63 changes: 32 additions & 31 deletions dist/index.js → dist/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
return '' + value.substr(0, value.length - 4).replace(/[\w]/g, 'X') + value.substr(-4);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ein-validator",
"version": "0.0.2",
"version": "1.0.0",
"description": "Employer Identification Number validator and masker",
"keywords": [
"EIN",
Expand Down

0 comments on commit 8428305

Please sign in to comment.