@ptolemy2002/regex-utils 2.6.0 → 2.6.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/dist/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export declare function isValidRegex(value: string, flags?: string): boolean;
17
17
  export declare function isValidRegexFlags(value: string): boolean;
18
18
  export type ZodValidator<O> = (v: O) => boolean;
19
19
  export type ZodValidatorWithErrors<O> = (v: O) => true | string | string[];
20
+ export declare function isZodError(err: unknown): err is ZodError;
20
21
  export type InterpretZodErrorOptions = {
21
22
  prefix?: string | string[];
22
23
  separator?: string;
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ exports.regexMatchWhole = regexMatchWhole;
10
10
  exports.transformRegex = transformRegex;
11
11
  exports.isValidRegex = isValidRegex;
12
12
  exports.isValidRegexFlags = isValidRegexFlags;
13
+ exports.isZodError = isZodError;
13
14
  exports.interpretZodError = interpretZodError;
14
15
  exports.zodValidate = zodValidate;
15
16
  exports.zodValidateWithErrors = zodValidateWithErrors;
@@ -111,6 +112,9 @@ function isValidRegex(value, flags = "") {
111
112
  function isValidRegexFlags(value) {
112
113
  return /^[gimsuy]*$/.test(value);
113
114
  }
115
+ function isZodError(err) {
116
+ return Boolean(err && (err instanceof zod_1.ZodError || err.name === 'ZodError'));
117
+ }
114
118
  function interpretZodError(e, { prefix, separator = "." } = {}) {
115
119
  const { errors } = e;
116
120
  function formatIssue(issue) {
@@ -150,7 +154,7 @@ function zodValidate(p) {
150
154
  }
151
155
  class ZodInterpretedError extends Error {
152
156
  constructor(message = null, { prefix, joinSeparator = "\n", pathSeparator = "." } = {}) {
153
- if (message instanceof zod_1.ZodError)
157
+ if (isZodError(message))
154
158
  message = interpretZodError(message, { prefix, separator: pathSeparator });
155
159
  super(Array.isArray(message) ? message.join(joinSeparator) : message ?? undefined);
156
160
  this.zodMessage = message;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/regex-utils",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",