waltronics-types 1.0.2 → 1.0.4

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