Skip to content

Commit

Permalink
Merge pull request #8 from Glazy/cjs
Browse files Browse the repository at this point in the history
Add CommonJS export alongside ESM
  • Loading branch information
Glazy authored Feb 25, 2025
2 parents 3cd251f + 6d6f77d commit 87ccb80
Show file tree
Hide file tree
Showing 8 changed files with 3,365 additions and 343 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.prettierrc.json
lib/
test/
tsconfig.json
tsconfig.*.json

26 changes: 8 additions & 18 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,14 @@ export const withZodSchema =
if (result.success) return {}

return result.error.issues.reduce((acc, curr) => {
if (curr.path.length) {
return merge(
acc,
curr.path.reduceRight(
(errors, pathSegment) => ({
[pathSegment]: !Object.keys(errors).length
? curr.message
: errors,
}),
{}
)
return merge(
acc,
curr.path.reduceRight(
(errors, pathSegment) => ({
[pathSegment]: !Object.keys(errors).length ? curr.message : errors,
}),
{}
)
}

const key = curr.path[0]
return {
...acc,
[key]: curr.message,
}
)
}, {})
}
Loading

0 comments on commit 87ccb80

Please sign in to comment.