Repository URL to install this package:
|
Version:
3.5.2 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const exotic_1 = require("exotic");
const isValidExpiryDate_1 = require("./isValidExpiryDate");
// time match hours, minutes, and seconds, 24-hour clock
// const matchTimeString = /^(2[0-3]|[01]?[0-9]):([0-5]?[0-9]):([0-5]?[0-9])$/
// // dateString match m/d/yy and mm/dd/yyyy, allowing any combination of one or two digits for the day and month, and two or four digits for the year
// const matchFullDate = /^(1[0-2]|0?[1-9])([\/-])(3[01]|[12][0-9]|0?[1-9])(?:\2)(?:[0-9]{2})?[0-9]{2}$/
// const matchMonth = /^[0-9]*$/gm
const matchMonthSpecicalChar = /^\d{0,2}(?:\.\d)?$/;
// function isValidMonth(value: string | Date): boolean {
// // .value == new Date().getFullYear()
// const isBeforeOneMonthAhead = value < new Date().getMonth() + 1
// // The credit card has expired. Choose a different expiration date.
// if (isBeforeOneMonthAhead) {
// return false
// }
// return true
// }
/**
* @see https://date-fns.org/
*
* @todo - use date_fns
* @todo - use in the dateParse util
* @todo - use in time atom
*/
// const monthValidateToZero = item => {
// const zero = 0
// const value = item.length >= 2 ? item : zero + item
// return value
// }
const matchLimit = (month) => {
// const removeSpecialCharacters = month.replace(matchMonthSpecicalChar, '')
// const validateToZero = monthValidateToZero(month)
return month > 0 && month <= 12;
};
exports.monthValidationForYear = (month, year) => {
if (year === exotic_1.toNumber(isValidExpiryDate_1.currentYear) ||
year === exotic_1.toNumber(isValidExpiryDate_1.currentYearTwoDigit)) {
return isValidExpiryDate_1.currentMonth <= month;
}
else {
return matchLimit(month);
}
};
// function isValidDate() {
// //
// }
// @observer
// extends React.Component
class ExpiryDateValidation {
constructor() {
this.isValidMonth = (year, month) => {
if (month &&
exports.monthValidationForYear(month, year) &&
matchMonthSpecicalChar.test(month)) {
return true;
}
else {
return false;
}
};
this.isValidYear = (year, month) => {
const expiryYearLength = year.toString().length;
const validYear = false;
if ((expiryYearLength === 4 && year >= exotic_1.toNumber(isValidExpiryDate_1.currentYear)) ||
(expiryYearLength === 2 && year >= exotic_1.toNumber(isValidExpiryDate_1.currentYearTwoDigit))) {
const result = isValidMonth(year, month);
// result ? this.isValidMonth(year, month) : false
return result;
}
return validYear;
};
}
isValidTimeOrDay() {
//
}
}
const expiryDate = new ExpiryDateValidation();
exports.expiryDate = expiryDate;
const isValidMonth = expiryDate.isValidMonth;
exports.isValidMonth = isValidMonth;
const isValidYear = expiryDate.isValidYear;
exports.isValidYear = isValidYear;
//# sourceMappingURL=isValidDates.js.map