Skip to content
This repository has been archived by the owner on Nov 16, 2018. It is now read-only.

Commit

Permalink
Merge pull request #5 from dhershman1/development
Browse files Browse the repository at this point in the history
v2.2.0
  • Loading branch information
dhershman1 authored Sep 6, 2018
2 parents 02fe0f6 + 11e7e89 commit 933bfcf
Show file tree
Hide file tree
Showing 20 changed files with 2,082 additions and 2,755 deletions.
6 changes: 0 additions & 6 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
},
"modules": false
}
],
[
"@babel/preset-stage-2",
{
"decoratorsLegacy": true
}
]
],
"exclude": "node_modules/**"
Expand Down
178 changes: 19 additions & 159 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,174 +42,34 @@ Browser

You can find most of the documentation for simple card here: https://www.dusty.codes/simple-card

## Methods
## Modular

As of v2.0.0 simple-card has been broken down to functions that can be used individually.
Simple Card is completely modular which means each piece of functionality can be imported by itself directly, or with destructuring.

All methods sanatize the strings (Remove whitespace or special characters like dashes)

### validate(card)

This is the primary validation function which runs the entire process of validating if the card number and cvn are valid, making sure it isn't expired, and making sure the card type matches the cvn provided.

#### Arguments

- `card` - `Object`: The card object to validate
- `card.number` - `String|Number`: The credit card number
- `card.cvn` - `String|Number`: The credit card CVN/Security Code
- `card.date` - `String`: The credit card expiration date

#### Return

Returns an object with an `isValid` and several other info props with card information

- `isValid` - `Boolean`: The Boolean whether or not the value passed the validation
- `cardType` - `String`: The found card type
- `cvnType` - `String`: The found CVN type
- `isExpired` - `Boolean`: Boolean which depends on if the card was expired or not
- `match` - `String`: A simple string which states if the cvn matched the card number or not

#### Usage
Example:

```js
import validate from 'simple-card/validate';

const cardObj = {
number: '4111111111111111',
cvn: '342',
date: currentDate // A simple var which is a string for the current date
};

validate(cardObj); // => { isValid: true, cardType: 'visa', cvnType: 'norm', expired: 'Not Expired', info: '' }
import validate from 'simple-card/validate'
import num from 'simple-card/number'
import cvn from 'simple-card/cvn'
import expired from 'simple-card/expired'
import matches from 'simple-card/matches'

const badCardObj = {
number: '4111111111111111',
cvn: '3432',
date: currentDate // A simple var which is a string for the current date
};

validate(badCardObj); // => { isValid: false, cardType: 'visa', cvnType: 'norm', expired: 'Not Expired', info: 'CVN does not match the found card type' }
// Or with destructuring

import { validate, number, cvn, matches, expired } from 'simple-card'
```

### number(cardNum)

This is the credit card number validation function, uses a luhn algorithm to strictly validate the number

#### Arguments

- `cardNum` - `String|Number`: The credit card number to validate

#### Return

Returns an object with an `isValid` prop and a `cardType` prop.

- `isValid` - `Boolean`: The Boolean whether or not the value passed the validation
- `cardType` - `String`: The info property is usually what comes back as the Card type
- Possible Values:
- `'visa'`: The card number is a `Visa` type of number
- `'discover'`: The card number is a `Discover` type of number
- `'master'`: The card number is a `Master Card` type of number
- `'amex'`: The number is an `American Express` type of number
- `'Invalid Card Number'`: The provided Number failed validation

#### Usage

```javascript
import number from 'simple-card/number';

number('4111111111111111'); // => { isValid: true, cardType: 'visa' }
number(4111111111111111); // => { isValid: true, cardType: 'visa' }
number('33222123'); // => { isValid: false, cardType: 'Invalid Card Number' }
number(33222123); // => { isValid: false, cardType: 'Invalid Card Number' }
```

### cvn(cardCvn)

This is the cvn or security code validation function. Its job essentially just makes sure its a correct length and doesn't contain any incorrect characters

#### Arguments

- `cardCVN` - `String|Number`: The CVN or security code to validate

#### Return
You can then call each function individually.

Returns an object with an `isValid` prop and a `cvnType` prop.
This also works with `commonjs` you just need to point directly to the file you want

- `isValid` - `Boolean`: The Boolean whether or not the value passed the validation
- `cvnType` - `String`: The info property is usually what comes back as the CVN type
- Possible Values:
- `'norm'`: normal 3 digit code
- `'amex'`: amex 4 digit code
- `'Invalid CVN Code'`: The provided CVN failed validation
**NOTE:** In order to use `validate` you need to pass a full card object to it like so:

#### Usage

```javascript
import cvn from 'simple-card/cvn';

cvn('333'); // => { isValid: true, cvnType: 'norm' }
cvn(333); // => { isValid: true, cvnType: 'norm' }
cvn('4444'); // => { isValid: true, cvnType: 'amex' }
cvn(4444); // => { isValid: true, cvnType: 'amex' }
cvn('55555'); // => { isValid: false, cvnType: 'Invalid CVN Code' }
cvn(55555); // => { isValid: false, cvnType: 'Invalid CVN Code' }
```

### expired(date)

This function accepts a String of the card expiration date to validate if the card is currently expired or not

#### Arguments

- `date` - `String`: Must be a string this is the date we wish to validate

#### Return

Returns an object with an `isValid` prop and a `isExpired` prop.

- `isValid` - `Boolean`: The Boolean whether or not the value passed the validation
- `isExpired` - `Boolean`: Boolean for true if it is expired false if it isn't

#### Usage

```javascript
import expired from 'simple-card/expired';

// Assuming "currDate" is a variable that holds the current date in a XX/XX format
expired(currDate); // => { isValid: true, isExpired: false }
expired('01/18'); // => { isValid: false, isExpired: true }
```

### matches(cvn, cardNum)

This function takes the cvn and card number, fetches the card type from the number and then validates that the cvn matches up with the card type.

#### Arguments

- `cvn` - `String|Number`: The card cvn to compare with
- `cardNum` - `String|Number`: The cards number to use to fetch the type for comparison

#### Return

Returns an object with an `isValid` prop and a `match` prop.

- `isValid` - `Boolean`: The Boolean whether or not the value passed the validation
- `match` - `String`: The String reply on if the card type matches the cvn provided
- Possible Values
- `'card type matches cvn'` if the match is valid
- `'cvn does not match card type'` if the match is invalid

#### Usage

```javascript
import matches from 'simple-card/matches';

// Assuming "amexCardNumber" is a valid American Express Credit Card Number
matches('333', '4111111111111111'); // => { isValid: true, match: 'card type matches cvn' }
matches(333, 4111111111111111); // => { isValid: true, match: 'card type matches cvn' }
matches('4444', amexCardNumber); // => { isValid: true, match: 'card type matches cvn' }
matches(4444, amexCardNumber); // => { isValid: true, match: 'card type matches cvn' }
matches('4444', '4111111111111111'); // => { isValid: false, match: 'cvn does not match card type' }
matches(4444, 4111111111111111); // => { isValid: false, match: 'cvn does not match card type' }
```js
{
number: '4111 1111 1111 1111',
cvn: '342',
date: '12/20'
}
```
25 changes: 25 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Changelog

## v2.2.0

### New

- Added unit tests for internal functions

### Improved

- Added my Kyanite Library to make use of utilities
- Fixed current linter issues
- Removed slow `for in` loop for getting the card type
- Made expired functionality no longer statically use `20` if only 2 digits are passed in for a year
- Heavy optimizations to `cvn` functionality
- Removed unneeded processing
- Cleaned up code base
- Removed unneeded code
- Optimizations to `match` functionality
- Tweaked Luhn Algorithm for easier catch on non-number cards
- Code optimizations within the number validation function
- Re wrote card type functionality from the ground up, improving performance
- Rebuilt validation flow taking advantage of the Kyanite library
- Re structured the flow of the expired functionality
- Updated all dev dependencies
- Better sanitization of data, cleaning up non-digits from data strings

## v2.1.2

- Hot fix for documentation bug
Expand Down
Loading

0 comments on commit 933bfcf

Please sign in to comment.