-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhanced typings with optional environment variables #194
Changes from 1 commit
1c32939
9741e97
9727612
bfa3d41
224d1bd
ce1007f
99002f5
8ecd933
328e056
e38457c
9474d47
4f25405
a9015bb
daa54e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules | |
coverage | ||
npm-debug.log | ||
yarn-error.log | ||
dist | ||
dist | ||
.vscode |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,8 @@ Each validation function accepts an (optional) object with the following attribu | |
|
||
## Custom validators | ||
|
||
### Basic usage | ||
|
||
You can easily create your own validator functions with `envalid.makeValidator()`. It takes | ||
a function as its only parameter, and should either return a cleaned value, or throw if the | ||
input is unacceptable: | ||
|
@@ -150,6 +152,16 @@ const env = cleanEnv(process.env, { | |
}); | ||
``` | ||
|
||
### TypeScript users | ||
|
||
You can use either one of `makeBaseValidator`, `makeExactValidator` and `makeMarkupValidator` | ||
depending on your use case: | ||
|
||
- `makeBaseValidator<BaseT>` when you want the output to be narrowed-down to a subtype of `BaseT` (e.g. `str`). | ||
- `makeExactValidator<T>` when you want the output to be widened to `T` (e.g. `bool`). | ||
- `makeMarkupValidator` for input which can produce arbitrary output types (e.g. `json`). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if it makes sense to expose There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking query parameters, e.g. PS1: didn't test but I think we should also forbid specs with choices in markup validators, correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Also re There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well, with one important exception: Yet, I'm happy to not export |
||
|
||
Note that `makeValidator` is an alias for `makeBaseValidator` which should cover most of use-cases. | ||
jsamr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Error Reporting | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably use examples of each case (makeValidator vs makeExactValidator) here as I don't think it'll be clear to most readers without diving into the source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if that's enough: 9727612
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't find the comment about formatting again; but fixed it here: ce1007f