Repository URL to install this package:
|
Version:
2.7.6 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const exotic_1 = require("exotic");
const isValidDates_1 = require("./isValidDates");
exports.isValidMonth = isValidDates_1.isValidMonth;
exports.isValidYear = isValidDates_1.isValidYear; // should stare
const currentDate = new Date();
const currentMonth = currentDate.getMonth() + 1;
exports.currentMonth = currentMonth;
const currentYear = String(currentDate.getFullYear());
exports.currentYear = currentYear;
const currentYearTwoDigit = String(currentDate.getFullYear()).slice(2, 4);
exports.currentYearTwoDigit = currentYearTwoDigit;
const toFormatted = _date => {
// 01/10 => 01/2010
const date = _date.length === 5 ? _date.replace('/', '20') : _date;
const formattedDate = date.replace(/[^0-9]/g, '');
const formattedMonth = formattedDate.replace(/^([2-9])|00/, '0$1').slice(0, 2).replace(/^([1][3-9])/, '1');
const formattedYear = formattedDate.slice(2, 4).replace(/^([0|4-9]\d+|[0|4-9])/, '');
const obj = {
date: formattedDate,
formattedMonth,
formattedYear,
month: exotic_1.toNumber(formattedMonth),
year: exotic_1.toNumber(formattedYear)
};
return obj;
};
/**
* @todo validator story is not aligned with this
*/
function isValidExpiryDate(date) {
const {
expiryYear,
expiryMonth,
validationType
} = date;
const year = expiryYear.value;
const month = expiryMonth.value;
const isWithinMonthRange = month > 0 && month <= 12;
const matchMonthSpecicalChar = /^\d{0,2}(?:\.\d)?$/;
if (!isWithinMonthRange) {
console.warn('isWithinMonthRange');
return false;
}
if (validationType == 'month') {
return month > 0 && month <= 12 && matchMonthSpecicalChar.test(month);
}
if (year && validationType == 'year') {
const yearValidation = isValidDates_1.isValidYear(year, month);
return yearValidation;
} else {
return false;
}
}
exports.isValidExpiryDate = isValidExpiryDate;
exports.default = isValidExpiryDate; //# sourceMappingURL=isValidExpiryDate.js.map