Skip to content

Commit

Permalink
Merge pull request #54 from ContaAzul/v2.1.1
Browse files Browse the repository at this point in the history
V2.1.1
  • Loading branch information
fernahh authored Jul 11, 2017
2 parents 7040aa2 + ea4fb72 commit 7383bf1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 deletions.
21 changes: 11 additions & 10 deletions dist/creditcard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* creditcard.js v2.1.0
* creditcard.js v2.1.1
* Created by @ContaAzul.
*
* Licensed MIT.
Expand Down Expand Up @@ -36,7 +36,6 @@ var CreditCard = function () {
key: 'getCreditCardNameByNumber',
value: function getCreditCardNameByNumber(number) {
var INVALID_CARD_MESSAGE = 'Credit card is invalid!';
if (!this.isValid(number)) return INVALID_CARD_MESSAGE;

var CREDIT_CARD_LIST = this.retrieveCreditCardList();

Expand All @@ -62,18 +61,20 @@ var CreditCard = function () {
}
}, {
key: 'isExpirationDateValid',
value: function isExpirationDateValid(month, year) {
var m = month;
var y = year;
value: function isExpirationDateValid(paramMonth, paramYearn) {
var month = parseInt(paramMonth, 10);
var year = parseInt(paramYearn, 10);

m = parseInt(m, 10);
y = parseInt(y, 10);
var currentYear = new Date().getFullYear();
var currentMonth = new Date().getMonth() + 1;

if (isNaN(m) || isNaN(y)) return false;
if (isNaN(month) || isNaN(year)) return false;

if (m < 1 || m > 12) return false;
if (year === currentYear && month < currentMonth) return false;

return !(y < 1000 || y >= 3000);
if (month < 1 || month > 12) return false;

return !(year < 1000 || year >= 3000);
}
}]);

Expand Down
4 changes: 2 additions & 2 deletions dist/creditcard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "creditcard.js",
"version": "2.1.0",
"version": "2.1.1",
"description": "A simple library for credit-card validation in JavaScript",
"main": "dist/creditcard.min.js",
"repository": "ContaAzul/creditcard.js",
Expand Down
19 changes: 18 additions & 1 deletion specs/creditCard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ describe('CreditCard', () => {
elo: '5041756758046020',
amex: '373257135458763',
aura: '5078601870000127985',
hiper: '6062825303833679'
hiper: '6062825303833679',
visaMask: '4532000000000000'
};
});

describe('#validadeExpiryDate', () => {
beforeEach(() => {
jasmine.clock().install();
jasmine.clock().mockDate(new Date(2017, 6, 10));
});

afterEach(() => jasmine.clock().uninstall());

it('should return true with its a VALID date', () => {
expect(creditcard.isExpirationDateValid('10', '2020')).toBeTruthy();
});
Expand All @@ -31,6 +39,10 @@ describe('CreditCard', () => {
it('should return false with empty month or year', () => {
expect(creditcard.isExpirationDateValid('', '')).toBeFalsy();
});

it('should return false when month is past', () => {
expect(creditcard.isExpirationDateValid('01', '2017')).toBeFalsy();
});
});

describe('#validadeCreditCard', () => {
Expand Down Expand Up @@ -96,6 +108,11 @@ describe('CreditCard', () => {
expect(creditCardName).toBe('Hipercard');
});

it('should return valid name for mask number', () => {
let creditCardName = creditcard.getCreditCardNameByNumber(CREDIT_CARDS.visaMask);
expect(creditCardName).toBe('Visa');
});

it('should return false', () => {
let creditCardName = creditcard.getCreditCardNameByNumber(INVALID_CREDIT_CARD);
expect(creditCardName).toBe('Credit card is invalid!');
Expand Down
21 changes: 11 additions & 10 deletions src/creditCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class CreditCard {

getCreditCardNameByNumber(number) {
const INVALID_CARD_MESSAGE = 'Credit card is invalid!';
if (!this.isValid(number))
return INVALID_CARD_MESSAGE;

let CREDIT_CARD_LIST = this.retrieveCreditCardList();

Expand All @@ -43,20 +41,23 @@ class CreditCard {
return regex.test(code);
}

isExpirationDateValid(month, year) {
let m = month;
let y = year;
isExpirationDateValid(paramMonth, paramYearn) {
const month = parseInt(paramMonth, 10);
const year = parseInt(paramYearn, 10);

m = parseInt(m, 10);
y = parseInt(y, 10);
const currentYear = new Date().getFullYear();
const currentMonth = new Date().getMonth() + 1;

if (isNaN(m) || isNaN(y))
if (isNaN(month) || isNaN(year))
return false;

if (m < 1 || m > 12)
if (year === currentYear && month < currentMonth)
return false;

return !(y < 1000 || y >= 3000);
if (month < 1 || month > 12)
return false;

return !(year < 1000 || year >= 3000);
}
}

Expand Down

0 comments on commit 7383bf1

Please sign in to comment.