@ptolemy2002/regex-utils 3.0.0 → 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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -15
- package/package.json +1 -1
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>`.
|
|
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.
|
|
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 = {
|
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 {
|
|
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 (
|
|
133
|
+
if (issues.length === 0)
|
|
144
134
|
return null;
|
|
145
|
-
if (
|
|
146
|
-
return formatIssue(
|
|
147
|
-
return
|
|
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) => {
|