waltronics-types 1.0.4 → 1.0.7
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/Validate.ts +45 -23
- package/package.json +2 -2
package/Validate.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import validator from "validator";
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const VIN = /^[A-HJ-NPR-Z0-9]{17}$/;
|
|
5
|
+
export const UUID = /^[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}$/;
|
|
6
|
+
export const SQL_DATE = /^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}(:[0-9]{2}$|:[0-9]{2}.[0-9]{3}$)/;
|
|
7
|
+
|
|
8
|
+
export const isName = z.string().trim().min(2, "Must enter a name.").max(50, "Must enter a name less than 50 characters.").regex(/^[A-Za-z\s'-]*$/, "Must enter a name without symbols.").transform(s => {
|
|
5
9
|
return s
|
|
6
10
|
.replace(/\s+/g, ' ')
|
|
7
11
|
.split(/\s/)
|
|
@@ -12,30 +16,30 @@ export const isName: z.ZodType = z.string().trim().min(2, "Must enter a name.").
|
|
|
12
16
|
})
|
|
13
17
|
;
|
|
14
18
|
|
|
15
|
-
export const isEmail
|
|
19
|
+
export const isEmail = z.string().trim().toLowerCase().email().max(320);
|
|
16
20
|
|
|
17
|
-
export const isPhone
|
|
21
|
+
export const isPhone = z.string().trim().refine(s => {
|
|
18
22
|
const hasFormat = !!s.match(/[0-9]{3}-[0-9]{3}-[0-9]{4}/);
|
|
19
23
|
const isMobilePhone = validator.isMobilePhone("1" + s.replaceAll("-", ""), "en-US")
|
|
20
24
|
return hasFormat && isMobilePhone;
|
|
21
25
|
}, "Must enter a phone number in the format 123-456-7890.")
|
|
22
26
|
;
|
|
23
27
|
|
|
24
|
-
export const isDate
|
|
25
|
-
export const isMoney
|
|
26
|
-
export const isVIN
|
|
27
|
-
export const isInteger
|
|
28
|
-
export const isIntegerArray
|
|
29
|
-
export const isUUID
|
|
30
|
-
export const isUUIDArray
|
|
31
|
-
export const isBit
|
|
28
|
+
export const isDate = z.string().trim().regex(/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}(:[0-9]{2}$|:[0-9]{2}.[0-9]{3}$)/);
|
|
29
|
+
export const isMoney = z.coerce.number();
|
|
30
|
+
export const isVIN = z.string().trim().regex(/^[A-HJ-NPR-Z0-9]{17}$/, "Must enter a valid VIN.")
|
|
31
|
+
export const isInteger = z.coerce.number().int();
|
|
32
|
+
export const isIntegerArray = z.array(z.coerce.number().int());
|
|
33
|
+
export const isUUID = z.string().refine(s => !!s.match(UUID));
|
|
34
|
+
export const isUUIDArray = z.array(z.string()).refine(ids => ids.every(id => !!id.match(UUID)));
|
|
35
|
+
export const isBit = z.string().trim().refine(s => s === "0" || s === "1");
|
|
32
36
|
|
|
33
|
-
export const isID
|
|
37
|
+
export const isID = z.union([
|
|
34
38
|
z.literal(""),
|
|
35
39
|
z.coerce.number()
|
|
36
40
|
]);
|
|
37
41
|
|
|
38
|
-
export const hasLengthAndClean = (data: {min: number; max: number; name: string})
|
|
42
|
+
export const hasLengthAndClean = (data: {min: number; max: number; name: string}) => {
|
|
39
43
|
return z
|
|
40
44
|
.string()
|
|
41
45
|
.trim()
|
|
@@ -46,43 +50,43 @@ export const hasLengthAndClean = (data: {min: number; max: number; name: string}
|
|
|
46
50
|
;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
export const isCode
|
|
53
|
+
export const isCode = hasLengthAndClean({
|
|
50
54
|
min: 1,
|
|
51
55
|
max: 100,
|
|
52
56
|
name: "code"
|
|
53
57
|
});
|
|
54
58
|
|
|
55
|
-
export const isMessage
|
|
59
|
+
export const isMessage = hasLengthAndClean({
|
|
56
60
|
min: 1,
|
|
57
61
|
max: 500,
|
|
58
62
|
name: "message"
|
|
59
63
|
});
|
|
60
64
|
|
|
61
|
-
export const isHead
|
|
65
|
+
export const isHead = hasLengthAndClean({
|
|
62
66
|
min: 1,
|
|
63
67
|
max: 100,
|
|
64
68
|
name: "value"
|
|
65
69
|
});
|
|
66
70
|
|
|
67
|
-
export const isBody
|
|
71
|
+
export const isBody = hasLengthAndClean({
|
|
68
72
|
min: 1,
|
|
69
73
|
max: 500,
|
|
70
74
|
name: "value"
|
|
71
75
|
});
|
|
72
76
|
|
|
73
|
-
export const isPartName
|
|
77
|
+
export const isPartName = hasLengthAndClean({
|
|
74
78
|
min: 1,
|
|
75
79
|
max: 100,
|
|
76
80
|
name: "name"
|
|
77
81
|
});
|
|
78
82
|
|
|
79
|
-
export const isPartNumber
|
|
83
|
+
export const isPartNumber = hasLengthAndClean({
|
|
80
84
|
min: 1,
|
|
81
85
|
max: 100,
|
|
82
86
|
name: "name"
|
|
83
87
|
});
|
|
84
88
|
|
|
85
|
-
export const isCCN
|
|
89
|
+
export const isCCN = z.string().trim().refine(s => {
|
|
86
90
|
const validLength = s.length >= 13 && s.length <= 16;
|
|
87
91
|
|
|
88
92
|
const providers = ["visa", "amex", "mastercard"] as any;
|
|
@@ -100,7 +104,7 @@ export const isCCN: z.ZodType = z.string().trim().refine(s => {
|
|
|
100
104
|
}, "Must enter a valid credit card number.")
|
|
101
105
|
;
|
|
102
106
|
|
|
103
|
-
export const isEXP
|
|
107
|
+
export const isEXP = z.string().trim().regex(/^(0[1-9]|1[0-2])[0-9]{2}$/, "Must enter a valid expiration date.").refine(s => {
|
|
104
108
|
const month = parseInt(s.substring(0, 2));
|
|
105
109
|
const year = 2000 + parseInt(s.substring(2, 4));
|
|
106
110
|
|
|
@@ -116,10 +120,28 @@ export const isEXP: z.ZodType = z.string().trim().regex(/^(0[1-9]|1[0-2])[0-9]{2
|
|
|
116
120
|
}, "Card has expired.");
|
|
117
121
|
;
|
|
118
122
|
|
|
119
|
-
export const isCreditCardType
|
|
123
|
+
export const isCreditCardType = z.enum(['VISA', 'MASTERCARD', 'AMEX']);
|
|
120
124
|
|
|
121
|
-
export const isRepair
|
|
125
|
+
export const isRepair = hasLengthAndClean({
|
|
122
126
|
min: 1,
|
|
123
127
|
max: 500,
|
|
124
128
|
name: "repair"
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
export const isClass = hasLengthAndClean({
|
|
132
|
+
min: 1,
|
|
133
|
+
max: 500,
|
|
134
|
+
name: "repair"
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
export const isDivision = hasLengthAndClean({
|
|
138
|
+
min: 1,
|
|
139
|
+
max: 50,
|
|
140
|
+
name: "value"
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
export const isService = hasLengthAndClean({
|
|
144
|
+
min: 1,
|
|
145
|
+
max: 50,
|
|
146
|
+
name: "value"
|
|
125
147
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "waltronics-types",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Contains the types used in the Waltronics application.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"validator": "^13.15.26",
|
|
14
|
-
"zod": "^
|
|
14
|
+
"zod": "^3.24.1"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@types/validator": "^13.15.10"
|