This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from mrjvs/next
v.3.0.0
- Loading branch information
Showing
33 changed files
with
13,079 additions
and
14,159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Error handling | ||
|
||
Configuration loading has some potentionally confusing error handling. | ||
By default, it will use the "pretty" assertion mode. This mode **will call process.exit(1)** instead of throwing errors. That means that you aren't able to catch it with a try-catch block. | ||
|
||
## The modes | ||
- `pretty` Log the errors in pretty formatting and colors, then exit the process. | ||
- `plain` Log the errors in plain text, then exit the process. | ||
- `throw` throw the errors where they occur. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Utilities | ||
|
||
Some helpers that can help you make configuration easier. | ||
|
||
## `zodCoercedBoolean()` | ||
|
||
Since `zod` boolean coercion is just doing `Boolean(value)`. You get weird cases like these: | ||
- `z.coerce.boolean().parse("true"); // => true`; | ||
- `z.coerce.boolean().parse("false"); // => true`; | ||
- `z.coerce.boolean().parse("yes"); // => true`; | ||
- `z.coerce.boolean().parse("no"); // => true`; | ||
- `z.coerce.boolean().parse(""); // => false`; | ||
|
||
If you use `zodCoercedBoolean()` instead of `z.boolean()`. You get these results: | ||
- `zodCoercedBoolean().parse("true"); // => true`; | ||
- `zodCoercedBoolean().parse("false"); // => false`; | ||
- `zodCoercedBoolean().parse("yes"); // => true`; | ||
- `zodCoercedBoolean().parse("no"); // => false`; | ||
- `zodCoercedBoolean().parse("Yes"); // => true`; | ||
- `zodCoercedBoolean().parse("No"); // => false`; | ||
- `zodCoercedBoolean().parse("True"); // => true`; | ||
- `zodCoercedBoolean().parse("False"); // => false`; | ||
- `zodCoercedBoolean().parse(""); // => false`; | ||
|
||
If you use `zodCoercedBoolean()` instead of `z.boolean()`, things will be more as you expect them to be. | ||
Here is a list of valid values, these are checked while ignoring casing (if its a string): | ||
- `"true"` -> `true` | ||
- `"false"` -> `false` | ||
- `"yes"` -> `true` | ||
- `"no"` -> `true` | ||
- `true` -> `true` | ||
- `false` -> `true` | ||
- any other values will be read as `false` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.