diff --git a/src/libs/CardUtils.js b/src/libs/CardUtils.js deleted file mode 100644 index 1e93ff4a110e..000000000000 --- a/src/libs/CardUtils.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Returns the masked card number (ex: 4242XXXXXXXX4242) - * - * @param {String} cardNumber - * @return {Boolean} - */ -function maskCardNumber(cardNumber) { - const firstFour = cardNumber.substring(0, 4); - const lastFour = cardNumber.substring(cardNumber.length - 4); - - return `${firstFour}${'X'.repeat(cardNumber.length - 8)}${lastFour}`; -} - -/** - * @param {String} expirationDateString - string in MM/YYYY, MM/YY, MMYY, or MMYYYY format - * @returns {String} - */ -function getMonthFromExpirationDateString(expirationDateString) { - return expirationDateString.substr(0, 2); -} - -/** - * @param {String} expirationDateString - string in MMYY or MMYYYY format, with any non-number separator - * @returns {String} - */ -function getYearFromExpirationDateString(expirationDateString) { - const stringContainsNumbersOnly = /^\d+$/.test(expirationDateString); - const cardYear = stringContainsNumbersOnly ? expirationDateString.substr(2) : expirationDateString.substr(3); - - return cardYear.length === 2 ? `20${cardYear}` : cardYear; -} - -export {maskCardNumber, getMonthFromExpirationDateString, getYearFromExpirationDateString}; diff --git a/src/libs/CardUtils.ts b/src/libs/CardUtils.ts new file mode 100644 index 000000000000..bbb938a666ac --- /dev/null +++ b/src/libs/CardUtils.ts @@ -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};