Skip to content

Commit

Permalink
Merge pull request #26100 from software-mansion-labs/kowczarz/refacto…
Browse files Browse the repository at this point in the history
…r-CardUtils

[No QA][TS migration] Migrate `CardUtils.js` lib to TypeScript
  • Loading branch information
deetergp authored Aug 29, 2023
2 parents 766dd65 + 8177e0a commit 0f5467d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
33 changes: 0 additions & 33 deletions src/libs/CardUtils.js

This file was deleted.

18 changes: 18 additions & 0 deletions src/libs/CardUtils.ts
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};

0 comments on commit 0f5467d

Please sign in to comment.