From 3677578712289aa2b4cc6c8fe5a99d01fdf98a50 Mon Sep 17 00:00:00 2001 From: Osho957 Date: Tue, 17 Sep 2024 22:58:55 +0530 Subject: [PATCH] (Bug Fix) isDate function: Add validation for delimiter and length checks to prevent undefined errors --- src/lib/isDate.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/lib/isDate.js b/src/lib/isDate.js index def28e094..dccddb144 100644 --- a/src/lib/isDate.js +++ b/src/lib/isDate.js @@ -1,8 +1,8 @@ import merge from "./util/merge"; const default_date_options = { - format: "YYYY/MM/DD", - delimiters: ["/", "-"], + format: 'YYYY/MM/DD', + delimiters: ['/', '-'], strictMode: false, }; @@ -24,13 +24,13 @@ function zip(date, format) { } export default function isDate(input, options) { - if (typeof options === "string") { + if (typeof options === 'string') { // Allow backward compatibility for old format isDate(input [, format]) options = merge({ format: options }, default_date_options); } else { options = merge(options, default_date_options); } - if (typeof input === "string" && isValidFormat(options.format)) { + if (typeof input === 'string' && isValidFormat(options.format)) { // Ensure the input contains at least one valid delimiter const hasValidDelimiter = options.delimiters.some((delimiter) => input.includes(delimiter) @@ -69,7 +69,7 @@ export default function isDate(input, options) { let fullYear = dateObj.y; // Check if the year starts with a hyphen - if (fullYear.startsWith("-")) { + if (fullYear.startsWith('-')) { return false; // Hyphen before year is not allowed } @@ -108,8 +108,7 @@ export default function isDate(input, options) { if (!options.strictMode) { return ( - Object.prototype.toString.call(input) === "[object Date]" && - isFinite(input) + Object.prototype.toString.call(input) === '[object Date]' && isFinite(input) ); }