-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26100 from software-mansion-labs/kowczarz/refacto…
…r-CardUtils [No QA][TS migration] Migrate `CardUtils.js` lib to TypeScript
- Loading branch information
Showing
2 changed files
with
18 additions
and
33 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
/** | ||
* @returns string with a month in MM format | ||
*/ | ||
function getMonthFromExpirationDateString(expirationDateString: string) { | ||
return expirationDateString.substring(0, 2); | ||
} | ||
|
||
/** | ||
* @returns string with a year in YY or YYYY format | ||
*/ | ||
function getYearFromExpirationDateString(expirationDateString: string) { | ||
const stringContainsNumbersOnly = /^\d+$/.test(expirationDateString); | ||
const cardYear = stringContainsNumbersOnly ? expirationDateString.substring(2) : expirationDateString.substring(3); | ||
|
||
return cardYear.length === 2 ? `20${cardYear}` : cardYear; | ||
} | ||
|
||
export {getMonthFromExpirationDateString, getYearFromExpirationDateString}; |