@dcrackel/hematournamentui 1.0.708 → 1.0.709

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.
@@ -1,29 +1,45 @@
1
- export function validateField(field, value) {
2
- const rules = {
3
- DisplayName: [
4
- { check: v => !v || v.trim().length === 0, message: 'Must have a name.' },
5
- { check: v => v.trim().length < 3, message: 'Must be at least 3 characters.' }
6
- ],
7
- LegalName: [
8
- { check: v => !v || v.trim().length === 0, message: 'Must have a name.' },
9
- { check: v => v.trim().length < 4, message: 'Must be at least 4 characters.' }
10
- ],
11
- EmailAddress: [
12
- { check: v => v && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v), message: 'Must be a valid email address.' }
13
- ],
14
- SelectedClub: [
15
- {
16
- check: v =>
17
- !v ||
18
- (typeof v === 'string' && v.trim().length === 0) ||
19
- (typeof v === 'object' && (!v.text || v.text.trim().length === 0)),
20
- message: 'Please select a Club.'
21
- }
22
- ]
23
- };
24
-
25
- const ruleSet = rules[field] || [];
26
- const failedRule = ruleSet.find(rule => rule.check(value));
27
-
28
- return failedRule ? { invalid: true, message: failedRule.message } : { invalid: false, message: '' };
29
- }
1
+ function isBlankHemaRatingsId(value) {
2
+ return value === undefined || value === null || (typeof value === 'string' && value.trim() === '');
3
+ }
4
+
5
+ function isPositiveIntegerId(value) {
6
+ if (!['string', 'number'].includes(typeof value)) return false;
7
+ if (typeof value === 'string' && !/^\d+$/.test(value.trim())) return false;
8
+ return Number.isSafeInteger(Number(value)) && Number(value) > 0;
9
+ }
10
+
11
+ function isInvalidHemaRatingsId(value) {
12
+ if (isBlankHemaRatingsId(value)) return false;
13
+ return !isPositiveIntegerId(value);
14
+ }
15
+
16
+ export function validateField(field, value) {
17
+ const rules = {
18
+ DisplayName: [
19
+ { check: v => !v || v.trim().length === 0, message: 'Must have a name.' },
20
+ { check: v => v.trim().length < 3, message: 'Must be at least 3 characters.' }
21
+ ],
22
+ LegalName: [
23
+ { check: v => !v || v.trim().length === 0, message: 'Must have a name.' },
24
+ { check: v => v.trim().length < 4, message: 'Must be at least 4 characters.' }
25
+ ],
26
+ EmailAddress: [
27
+ { check: v => v && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v), message: 'Must be a valid email address.' }
28
+ ],
29
+ HemaRatingsId: [{ check: isInvalidHemaRatingsId, message: 'Enter a positive whole-number ID, or leave it blank.' }],
30
+ SelectedClub: [
31
+ {
32
+ check: v =>
33
+ !v ||
34
+ (typeof v === 'string' && v.trim().length === 0) ||
35
+ (typeof v === 'object' && (!v.text || v.text.trim().length === 0)),
36
+ message: 'Please select a Club.'
37
+ }
38
+ ]
39
+ };
40
+
41
+ const ruleSet = rules[field] || [];
42
+ const failedRule = ruleSet.find(rule => rule.check(value));
43
+
44
+ return failedRule ? { invalid: true, message: failedRule.message } : { invalid: false, message: '' };
45
+ }