@ptolemy2002/regex-utils 2.6.2 → 4.0.0

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/README.md CHANGED
@@ -163,7 +163,7 @@ Checks if an unknown value is a ZodError. This is more reliable than using `inst
163
163
 
164
164
  ### interpretZodError
165
165
  #### Description
166
- Given a zod error, interprets it to `null` if no error is found, a single error message if there is a single error, or an array of error messages if there are multiple errors. The error messages will be in the format `<path>: <message>`. If the error is with function arguments, "arguments.<index>" will be appended to the end of the path. Similarly, if the error is with a function return value, "returnValue" will be appended to the end of the path. Note that for function arguments, only the first seen error will be reported.
166
+ Given a zod error, interprets it to `null` if no error is found, a single error message if there is a single error, or an array of error messages if there are multiple errors. The error messages will be in the format `<path>: <message>`.
167
167
 
168
168
  #### Parameters
169
169
  - `e` (`ZodError`): The zod error to be interpreted.
package/dist/index.d.ts CHANGED
@@ -24,7 +24,7 @@ export type InterpretZodErrorOptions = {
24
24
  };
25
25
  export declare function interpretZodError(e: ZodError, { prefix, separator }?: InterpretZodErrorOptions): string | string[] | null;
26
26
  export type ZodSafeParseable<O> = {
27
- safeParse: (v: unknown) => z.SafeParseReturnType<unknown, O>;
27
+ safeParse: (v: unknown) => z.ZodSafeParseResult<O>;
28
28
  };
29
29
  export declare function zodValidate<O>(p: ZodSafeParseable<O>): ZodValidator<O>;
30
30
  export type ZodValidateWithErrorsOptions = {
@@ -46,5 +46,31 @@ export declare function isValidEmail(v: string): boolean;
46
46
  export declare function isValidURL(v: string): boolean;
47
47
  export declare function isValidPhoneNumber(v: string): boolean;
48
48
  export declare function isValidSSN(v: string): boolean;
49
- export declare const ZodCoercedBooleanEnum: z.ZodEnum<["true", "false", "t", "f", "yes", "no", "y", "n", "1", "0", "on", "off"]>;
50
- export declare const ZodCoercedBoolean: z.ZodEffects<z.ZodEnum<["true", "false", "t", "f", "yes", "no", "y", "n", "1", "0", "on", "off"]>, boolean, "0" | "1" | "true" | "false" | "t" | "f" | "yes" | "no" | "y" | "n" | "on" | "off">;
49
+ export declare const ZodCoercedBooleanEnum: z.ZodEnum<{
50
+ 0: "0";
51
+ 1: "1";
52
+ true: "true";
53
+ false: "false";
54
+ t: "t";
55
+ f: "f";
56
+ yes: "yes";
57
+ no: "no";
58
+ y: "y";
59
+ n: "n";
60
+ on: "on";
61
+ off: "off";
62
+ }>;
63
+ export declare const ZodCoercedBoolean: z.ZodPipe<z.ZodEnum<{
64
+ 0: "0";
65
+ 1: "1";
66
+ true: "true";
67
+ false: "false";
68
+ t: "t";
69
+ f: "f";
70
+ yes: "yes";
71
+ no: "no";
72
+ y: "y";
73
+ n: "n";
74
+ on: "on";
75
+ off: "off";
76
+ }>, z.ZodTransform<boolean, "0" | "1" | "true" | "false" | "t" | "f" | "yes" | "no" | "y" | "n" | "on" | "off">>;
package/dist/index.js CHANGED
@@ -116,7 +116,7 @@ function isZodError(err) {
116
116
  return Boolean(err && (err instanceof zod_1.ZodError || err.name === 'ZodError'));
117
117
  }
118
118
  function interpretZodError(e, { prefix, separator = "." } = {}) {
119
- const { errors } = e;
119
+ const { issues } = e;
120
120
  function formatIssue(issue) {
121
121
  const { code, path: _path, message } = issue;
122
122
  let path = _path;
@@ -126,25 +126,15 @@ function interpretZodError(e, { prefix, separator = "." } = {}) {
126
126
  else if (Array.isArray(prefix)) {
127
127
  path = [...prefix, ...path];
128
128
  }
129
- if (code === "invalid_return_type") {
130
- const returnTypeIssue = issue.returnTypeError.errors[0];
131
- path = [...path, "returnType", ...returnTypeIssue.path];
132
- return `${path.join(separator)}: ${returnTypeIssue.message}`;
133
- }
134
- else if (code === "invalid_arguments") {
135
- const argumentsIssue = issue.argumentsError.errors[0];
136
- path = [...path, "arguments", ...argumentsIssue.path];
137
- return `${path.join(separator)}: ${argumentsIssue.message}`;
138
- }
139
129
  if (path.length === 0)
140
130
  return message;
141
131
  return `${path.join(separator)}: ${message}`;
142
132
  }
143
- if (errors.length === 0)
133
+ if (issues.length === 0)
144
134
  return null;
145
- if (errors.length === 1)
146
- return formatIssue(errors[0]);
147
- return errors.map((e) => formatIssue(e));
135
+ if (issues.length === 1)
136
+ return formatIssue(issues[0]);
137
+ return issues.map((e) => formatIssue(e));
148
138
  }
149
139
  function zodValidate(p) {
150
140
  return (v) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/regex-utils",
3
- "version": "2.6.2",
3
+ "version": "4.0.0",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,9 +27,9 @@
27
27
  "release-major": "bash ./scripts/release.sh major"
28
28
  },
29
29
  "peerDependencies": {
30
- "zod": "^3.23.8"
30
+ "zod": "^4.0.0"
31
31
  },
32
32
  "devDependencies": {
33
- "zod": "^3.23.8"
33
+ "zod": "^4.0.0"
34
34
  }
35
35
  }