-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Bug fixes and added more test cases
- Separated out formatter methods
- Loading branch information
Showing
16 changed files
with
1,217 additions
and
579 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* This method limit val between 1 to max | ||
* val and max both are passed as string | ||
**/ | ||
function limit(val, max) { | ||
if (val.length === 1 && val[0] > max[0]) { | ||
val = '0' + val; | ||
} | ||
|
||
if (val.length === 2) { | ||
if (Number(val) === 0) { | ||
val = '01'; | ||
|
||
//this can happen when user paste number | ||
} else if (val > max) { | ||
val = max; | ||
} | ||
} | ||
|
||
return val; | ||
} | ||
|
||
export function cardExpiry(val) { | ||
let month = limit(val.substring(0, 2), '12'); | ||
let date = limit(val.substring(2, 4), '31'); | ||
|
||
return month + (date.length ? '/' + date : ''); | ||
} |
Oops, something went wrong.