@ptolemy2002/regex-utils 2.2.0 → 2.2.1

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
@@ -127,7 +127,7 @@ Checks if a string is a valid set of regular expression flags.
127
127
 
128
128
  ### interpretZodError
129
129
  #### Description
130
- 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.
130
+ 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>`.
131
131
 
132
132
  #### Parameters
133
133
  - `e` (`ZodError`): The zod error to be interpreted.
package/dist/index.js CHANGED
@@ -113,11 +113,17 @@ function isValidRegexFlags(value) {
113
113
  }
114
114
  function interpretZodError(e) {
115
115
  const { errors } = e;
116
+ function formatIssue(issue) {
117
+ const { path, message } = issue;
118
+ if (path.length === 0)
119
+ return message;
120
+ return `${path.join(".")}: ${message}`;
121
+ }
116
122
  if (errors.length === 0)
117
123
  return null;
118
124
  if (errors.length === 1)
119
- return e.errors[0].message;
120
- return errors.map((e) => e.message);
125
+ return formatIssue(errors[0]);
126
+ return errors.map((e) => formatIssue(e));
121
127
  }
122
128
  function zodValidate(p) {
123
129
  return (v) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/regex-utils",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",