nox-validation 1.6.0 → 1.6.1
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.
- package/lib/helpers.js +2 -5
- package/lib/validate.js +53 -12
- package/package.json +1 -1
package/lib/helpers.js
CHANGED
|
@@ -1503,12 +1503,9 @@ const formatDate = ({
|
|
|
1503
1503
|
];
|
|
1504
1504
|
|
|
1505
1505
|
if (!formats.includes(format)) format = formats[0];
|
|
1506
|
-
|
|
1507
|
-
throw new RangeError("Invalid time value");
|
|
1508
|
-
}
|
|
1509
|
-
const dateObj = date instanceof Date ? date : new Date(date);
|
|
1506
|
+
|
|
1510
1507
|
const { year, month, day, hour, minute, second, dayPeriod } = getParts(
|
|
1511
|
-
|
|
1508
|
+
date,
|
|
1512
1509
|
timeZone
|
|
1513
1510
|
);
|
|
1514
1511
|
|
package/lib/validate.js
CHANGED
|
@@ -60,9 +60,20 @@ const typeChecks = {
|
|
|
60
60
|
}
|
|
61
61
|
return false;
|
|
62
62
|
},
|
|
63
|
-
[constants.types.TIME]: (val) =>
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
[constants.types.TIME]: (val, data) => {
|
|
64
|
+
if (val instanceof Date && !isNaN(val)) return true;
|
|
65
|
+
if (typeof val === "string") {
|
|
66
|
+
if (/^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)$/.test(val)) return true;
|
|
67
|
+
const parsed = Date.parse(val);
|
|
68
|
+
if (!isNaN(parsed)) {
|
|
69
|
+
if (data && data?.key && data?.updateValue) {
|
|
70
|
+
data.updateValue(data.key, new Date(val));
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
},
|
|
66
77
|
[constants.types.TIMESTAMP]: (val, data) => {
|
|
67
78
|
if (val instanceof Date && !isNaN(val)) return true;
|
|
68
79
|
if (typeof val === "string" && !isNaN(Date.parse(val))) {
|
|
@@ -411,6 +422,7 @@ const validateMetaRules = (
|
|
|
411
422
|
if (
|
|
412
423
|
(isEmpty(fieldValue) &&
|
|
413
424
|
required &&
|
|
425
|
+
!field?.meta?.hidden &&
|
|
414
426
|
![
|
|
415
427
|
constants.interfaces.FILES,
|
|
416
428
|
constants.interfaces.FILE,
|
|
@@ -423,11 +435,13 @@ const validateMetaRules = (
|
|
|
423
435
|
"none",
|
|
424
436
|
].includes(field?.meta?.interface)) ||
|
|
425
437
|
(field?.meta?.interface === constants.interfaces.TRANSLATIONS &&
|
|
438
|
+
!field?.meta?.hidden &&
|
|
426
439
|
language_codes?.length &&
|
|
427
440
|
!onlyFormFields) ||
|
|
428
441
|
([constants.interfaces.OBJECT, constants.interfaces.ITEMS].includes(
|
|
429
442
|
field?.meta?.interface
|
|
430
443
|
) &&
|
|
444
|
+
!field?.meta?.hidden &&
|
|
431
445
|
!onlyFormFields &&
|
|
432
446
|
getNodes)
|
|
433
447
|
) {
|
|
@@ -456,6 +470,7 @@ const validateMetaRules = (
|
|
|
456
470
|
const message = error_messages.REQUIRED.replace("{field}", label);
|
|
457
471
|
|
|
458
472
|
const buildError = (path, translated) => {
|
|
473
|
+
if (!isEmpty(getValue(formData, path))) return;
|
|
459
474
|
let obj = {
|
|
460
475
|
label,
|
|
461
476
|
fieldPath: path,
|
|
@@ -626,10 +641,6 @@ const handleRegexValidation = (
|
|
|
626
641
|
message = message
|
|
627
642
|
?.replace(`{field}`, fieldLabel)
|
|
628
643
|
?.replace(`{value}`, rule.value[0]);
|
|
629
|
-
console.log(
|
|
630
|
-
"[handleRegexValidation] Validation failed. Adding error. Message:",
|
|
631
|
-
message
|
|
632
|
-
);
|
|
633
644
|
addError(
|
|
634
645
|
currentPath,
|
|
635
646
|
{ label: fieldLabel, fieldPath: currentPath, description: "", message },
|
|
@@ -660,10 +671,40 @@ const validateOperatorRule = (
|
|
|
660
671
|
const isTime = field.type === constants.types.TIME;
|
|
661
672
|
const isArray = field.type === constants.types.ARRAY;
|
|
662
673
|
|
|
663
|
-
const parseTime = (
|
|
664
|
-
if (!
|
|
665
|
-
|
|
666
|
-
|
|
674
|
+
const parseTime = (value) => {
|
|
675
|
+
if (!value) return null;
|
|
676
|
+
|
|
677
|
+
const toSeconds = (str) => {
|
|
678
|
+
const [hh = 0, mm = 0, ss = 0] = str.split(":").map(Number);
|
|
679
|
+
return hh * 3600 + mm * 60 + ss;
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
if (value instanceof Date && !isNaN(value)) {
|
|
683
|
+
const timePart = formatDate({
|
|
684
|
+
date: value,
|
|
685
|
+
format: "DD/MM/YYYY HH:mm:ss",
|
|
686
|
+
timeZone,
|
|
687
|
+
}).split(" ")[1];
|
|
688
|
+
const totalSeconds = toSeconds(timePart);
|
|
689
|
+
return totalSeconds || null;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
if (typeof value === "string") {
|
|
693
|
+
if (/^\d{1,2}:\d{2}:\d{2}$/.test(value)) {
|
|
694
|
+
return toSeconds(value);
|
|
695
|
+
}
|
|
696
|
+
if (!isNaN(Date.parse(value))) {
|
|
697
|
+
const timePart = formatDate({
|
|
698
|
+
date: value,
|
|
699
|
+
format: "DD/MM/YYYY HH:mm:ss",
|
|
700
|
+
timeZone,
|
|
701
|
+
}).split(" ")[1];
|
|
702
|
+
const totalSeconds = toSeconds(timePart);
|
|
703
|
+
return totalSeconds || null;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
return null;
|
|
667
708
|
};
|
|
668
709
|
|
|
669
710
|
// Helper to parse date string to UTC midnight timestamp
|
|
@@ -700,7 +741,7 @@ const validateOperatorRule = (
|
|
|
700
741
|
}
|
|
701
742
|
if (isDateTime) {
|
|
702
743
|
if (forMessage) {
|
|
703
|
-
const format = field?.options?.format;
|
|
744
|
+
const format = field?.meta?.options?.format;
|
|
704
745
|
return formatDate({ date: value, format, timeZone });
|
|
705
746
|
}
|
|
706
747
|
// Return UTC timestamp for comparison
|