Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

iin-checker

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iin-checker - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

configs/patterns.js

7

CHANGELOG.md
# Changelog
## **0.1.8**
- [**#19**](https://github.com/Shortbreaks/iinChecker/issues/19) Added in a fall back to RegEx if all providers fail
- [**#17**](https://github.com/Shortbreaks/iinChecker/issues/17) Updated travis file so coveralls doesn't fail
- Fixed the grammer on the tests
- Made test to the same style as the others
- [**#11**](https://github.com/Shortbreaks/iinChecker/issues/11) Fixed input string issue
## **0.1.7**

@@ -4,0 +11,0 @@ - [**#10**](https://github.com/Shortbreaks/iinChecker/issues/10) Fixed issues not getting caught

2

lib/i18n/en.json
{
"PARAMETER_IIN_IS_UNDEFINED" : "Parameter \"iin\" is [undefined]",
"PARAMETER_IIN_IS_EMPTY" : "Parameter \"iin\" is [empty]",
"PARAMETER_IIN_IS_NOT_A_NUMBER" : "Parameter \"iin\" in not a number",
"PARAMETER_IIN_IS_NOT_LONG_ENOUGH" : "Parameter \"iin\" in not long enough (6 characters)",
"PARAMETER_CALLBACK_NOT_FUNCTION": "Parameter \"callback\" is not [function]"
}

@@ -27,9 +27,11 @@

this.brands = {
'VISA': 'VISA',
'MASTERCARD': 'MASTERCARD',
'AMEX': 'AMERICAN EXPRESS',
'DISCOVER': 'DISCOVER ',
'JCB': 'JCB',
'MAESTRO': 'MAESTRO',
'LASER': 'LASER',
VISA: 'VISA',
MASTERCARD: 'MASTERCARD',
AMEX: 'AMERICAN EXPRESS',
DISCOVER: 'DISCOVER',
DINERS: 'DINERS CLUB',
JCB: 'JCB',
MAESTRO: 'MAESTRO',
LASER: 'LASER',
UNKNOWN: this.nullValue
};

@@ -41,6 +43,9 @@ // DANKORT what do we do with this?

// DINERS has been added for RegEx, but both Robbin and BinList return these cards as DISCOVER
// TODO: Change this later to be consitent across RegEx and providers
this.types = {
'DEBIT': 'DEBIT',
'CREDIT': 'CREDIT',
'UNKNOWN': this.nullValue
DEBIT: 'DEBIT',
CREDIT: 'CREDIT',
UNKNOWN: this.nullValue
};

@@ -53,2 +58,3 @@

var self = this;
var cardInfo;
var providerDetails = providers[providerCount];

@@ -58,3 +64,3 @@ request( { url: providerDetails.domain + providerDetails.path + iin, json: true }, function( error, response, body ) {

// Remap the reply to match our schema
var cardInfo = providerDetails.map( body, self.nullValue );
cardInfo = providerDetails.map( body, self.nullValue );
// send the results back a-la-node

@@ -66,8 +72,33 @@ callback( null, cardInfo );

} else {
// Return the err in the error callback, or if no error send back the http status code
callback( error || response.statusCode );
// Maybe one last attempt here with RegEx? If that does not work then error
var patterns = require( '../configs/patterns' );
// Set out null info object
cardInfo = {
iin: iin,
brand: null,
issuer: self.nullValue,
type: self.nullValue,
category: self.nullValue,
country: self.nullValue
};
_.each( patterns, function( pattern ) {
var regex = new RegExp( pattern.expression );
if( !cardInfo.brand && regex.test( iin ) ) {
cardInfo.brand = self.brands[pattern.name];
}
} );
// See if RegEx worked
if ( cardInfo.brand && cardInfo.brand !== self.brands.UNKNOWN ) {
callback( null, cardInfo );
} else {
// Return the err in the error callback, or if no error send back the http status code
callback( error || response.statusCode );
}
}
}
} );
}
};
};

@@ -87,2 +118,3 @@

try {
if ( _.isUndefined( iin ) ) {

@@ -96,2 +128,13 @@ throw new TypeError( this.options.messages.PARAMETER_IIN_IS_UNDEFINED );

iin = String( iin );
// First up. Make sure we are passing a number in.
if( _.isNaN( parseInt( iin ) ) ) {
throw new TypeError( this.options.messages.PARAMETER_IIN_IS_NOT_A_NUMBER );
}
// Now make sure that we are passing in 6 characters
if( iin.length !== 6 ) {
throw new TypeError( this.options.messages.PARAMETER_IIN_IS_NOT_LONG_ENOUGH );
}
}

@@ -98,0 +141,0 @@ }

10

package.json
{
"name": "iin-checker",
"description": "Issuer identification number checker which returns details about a credit/debit card",
"version": "0.1.7",
"version": "0.1.8",
"homepage": "https://github.com/Shortbreaks/iinChecker",

@@ -27,7 +27,7 @@ "author": "Simon Wood <simon.wood@holidayextras.com> (https://github.com/Shortbreaks)",

"grunt-contrib-jshint": "^0.10.0",
"grunt-jscs": "^0.6.2",
"grunt-mocha-test": "^0.11.0",
"grunt-jscs": "^0.8.1",
"grunt-mocha-test": "^0.12.2",
"istanbul": "^0.3.0",
"mocha": "^1.21.4",
"nock": "^0.45.0"
"mocha": "^2.0.1",
"nock": "^0.48.2"
},

@@ -34,0 +34,0 @@ "dependencies": {

@@ -9,6 +9,9 @@ /* jshint -W098 */

// RegEx Constant
var REGEX = 'REGEX';
describe( '#pass in invalid params', function() {
it( 'should lookup a card with undefined iin and error gracefully', function( done ) {
iin.lookup( undefined, function( err, result ) {
err.should.be.a( 'object' );
err.should.be.an( 'object' );
err.message.should.equal( iin.options.messages.PARAMETER_IIN_IS_UNDEFINED );

@@ -20,3 +23,3 @@ done();

iin.lookup( '', function( err, result ) {
err.should.be.a( 'object' );
err.should.be.an( 'object' );
err.message.should.equal( iin.options.messages.PARAMETER_IIN_IS_EMPTY );

@@ -27,6 +30,20 @@ done();

it( 'should lookup a card with undefined callback and error gracefully', function( done ) {
result = iin.lookup( '411111' );
var result = iin.lookup( '411111' );
result.message.should.equal( iin.options.messages.PARAMETER_CALLBACK_NOT_FUNCTION );
done();
} );
it( 'should return an error of not a number', function( done ) {
iin.lookup( 'foobar', function( err, result ) {
err.should.be.an( 'object' );
err.message.should.equal( iin.options.messages.PARAMETER_IIN_IS_NOT_A_NUMBER );
done();
} );
} );
it( 'should return an error of not long enough', function( done ) {
iin.lookup( '123', function( err, result ) {
err.should.be.an( 'object' );
err.message.should.equal( iin.options.messages.PARAMETER_IIN_IS_NOT_LONG_ENOUGH );
done();
} );
} );
} );

@@ -37,6 +54,5 @@

// Lets read our providers in from the config and loop over them
providers.forEach( function( provider ) {
var stubRequest = function( iin ) {
var stubRequest = function( provider, iin ) {
// Don't stub our network requests if our provider is RegEx as it is not a network request
if ( provider.name !== REGEX ) {
// Make sure our string comparisons don't get caught out by case issues by converting to uppercase

@@ -48,9 +64,12 @@ if ( iin !== '111111' ) {

}
};
}
};
// This will stop all further calls to this provider from functioning...Please make sure you call this on the last line of your last test function
var breakProvider = function() {
nock( provider.domain ).persist().get( '*' ).reply( 500 );
};
// This will stop all further calls to this provider from functioning...Please make sure you call this on the last line of your last test function
var breakProvider = function( provider ) {
nock( provider.domain ).persist().get( '*' ).reply( 500 );
};
// Out repeatable tests
var commonTests = function( provider ) {
describe( '#lookup a card using ' + provider.name, function() {

@@ -60,3 +79,3 @@ var testGenCard;

var iinToLookup = '411111';
stubRequest( iinToLookup );
stubRequest( provider, iinToLookup );
iin.lookup( iinToLookup, function( err, result ) {

@@ -73,3 +92,3 @@ if ( err ) {

it( 'iin lookup returns card as an object', function( done ) {
testGenCard.should.be.a( 'object' );
testGenCard.should.be.an( 'object' );
done();

@@ -87,6 +106,6 @@ } );

} );
it( 'should lookup an invalid card and error gracefully', function( done ) {
var iinToLookup = '111111';
stubRequest( iinToLookup );
stubRequest( provider, iinToLookup );
iin.lookup( iinToLookup, function( err, result ) {

@@ -104,3 +123,3 @@ err.should.not.be.null;

var iinToLookup = '431940';
stubRequest( iinToLookup );
stubRequest( provider, iinToLookup );
iin.lookup( iinToLookup, function( err, result ) {

@@ -116,6 +135,14 @@ if ( err ) {

it( 'card is of type debit', function( done ) {
testVisaDebitCard.type.should.equal( iin.types.DEBIT );
done();
} );
// Alter test depending on if it is RegEx of a Provider Test
if ( provider.name === REGEX ) {
it( 'card is of type unknown', function( done ) {
testVisaDebitCard.type.should.equal( iin.types.UNKNOWN );
done();
} );
} else {
it( 'card is of type debit', function( done ) {
testVisaDebitCard.type.should.equal( iin.types.DEBIT );
done();
} );
}

@@ -132,3 +159,3 @@ it( 'card is of brand visa', function( done ) {

var iinToLookup = '518791';
stubRequest( iinToLookup );
stubRequest( provider, iinToLookup );
iin.lookup( iinToLookup, function( err, result ) {

@@ -144,14 +171,30 @@ if ( err ) {

it( 'card is of type credit', function( done ) {
testMasterCreditCard.type.should.equal( iin.types.CREDIT );
done();
} );
// Alter test depending on if it is RegEx of a Provider Test
if ( provider.name === REGEX ) {
it( 'card is of type unknown', function( done ) {
testMasterCreditCard.type.should.equal( iin.types.UNKNOWN );
done();
} );
} else {
it( 'card is of type credit', function( done ) {
testMasterCreditCard.type.should.equal( iin.types.CREDIT );
done();
} );
}
it( 'card is of brand mastercard', function( done ) {
testMasterCreditCard.brand.should.equal( iin.brands.MASTERCARD );
// This is the final test...we are all done with the provider, so let's mock them being broken, so that fallback will work for the subsequent provider
breakProvider();
done();
} );
} );
};
// Lets read our providers in from the config and loop over them
providers.forEach( function( provider ) {
commonTests( provider );
// This is the final test...we are all done with the provider, so let's mock them being broken, so that fallback will work for the subsequent provider
breakProvider( provider );
} );
// Because we have looped all providers and called 'breakProvider' on each we should be OK to test the RegEx version here.
commonTests( { name: REGEX } );

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc