ingeni-validation 1.1.4 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -220,32 +220,48 @@ async function isValidPin(pinCode) {
220
220
  }
221
221
 
222
222
 
223
- //Valid Date Time (isValidDate(value, "yyyy-mm-dd") , isValidDate(value, "yyyy-mm-dd h:i:s")
224
- function isValidDate(value, format) {
223
+ // Valid Date Time (isValidDate(value,"yyyy-mm-dd") , isValidDate(value,"yyyy-mm-dd h:i:s"))
225
224
 
226
- let regex;
225
+ function isValidDate(value, format) {
227
226
 
228
- switch (format.toLowerCase()) {
227
+ // Reject null, undefined
228
+ if (value === null || value === undefined) {
229
+ return false;
230
+ }
231
+
232
+ // Reject non-string values
233
+ if (typeof value !== "string") {
234
+ return false;
235
+ }
229
236
 
230
- case "yyyy-mm-dd":
231
- regex = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/;
232
- break;
237
+ // Reject empty or spaces
238
+ if (value.trim().length === 0) {
239
+ return false;
240
+ }
241
+
242
+ let regex;
233
243
 
234
- case "yyyy-mm-dd h:i:s":
235
- regex = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/;
236
- break;
244
+ switch (format.toLowerCase()) {
237
245
 
238
- default:
239
- return false;
240
- }
246
+ case "yyyy-mm-dd":
247
+ regex = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/;
248
+ break;
241
249
 
242
- if (!regex.test(value)) {
243
- return false;
244
- }
250
+ case "yyyy-mm-dd h:i:s":
251
+ regex = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/;
252
+ break;
245
253
 
246
- const d = new Date(value.replace(" ", "T"));
247
- return !isNaN(d.getTime());
248
- }
254
+ default:
255
+ return false;
256
+ }
257
+
258
+ if (!regex.test(value)) {
259
+ return false;
260
+ }
261
+
262
+ const d = new Date(value.replace(" ", "T"));
263
+ return !isNaN(d.getTime());
264
+ }
249
265
 
250
266
 
251
267
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ingeni-validation",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Ingeni Validation",
5
5
  "license": "ISC",
6
6
  "author": "",