Skip to content

Commit 6475cae

Browse files
committed
feat: 📝 Add documentation around built-in validators to the README.md
1 parent 6fe664d commit 6475cae

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,35 @@ await initVariable("SECRET", z.string(), 'xxx');
9494
await initVariable("SECRET", z.string().optional());
9595
```
9696

97+
## 🔧 Built-in Validators
98+
99+
> [!NOTE]
100+
> This feature is available starting from version v1.1.0.
101+
102+
Envar provides several built-in validators to simplify common validation tasks:
103+
104+
- `REQUIRED` - Ensures the variable is set and not `undefined`
105+
- `OPTIONAL` - Allows the variable to be `undefined`
106+
- `REQUIRED_NON_EMPTY` - Ensures the variable is set and not an empty string
107+
- `OPTIONAL_NON_EMPTY` - Allows the variable to be `undefined` or a non-empty string
108+
109+
Here's how you can use these validators:
110+
111+
```ts
112+
import {
113+
initVariable,
114+
REQUIRED,
115+
OPTIONAL,
116+
REQUIRED_NON_EMPTY,
117+
OPTIONAL_NON_EMPTY,
118+
} from "jsr:@wuespace/envar";
119+
120+
await initVariable("REQUIRED", REQUIRED); // Must be set
121+
await initVariable("OPTIONAL", OPTIONAL); // Can be undefined
122+
await initVariable("REQUIRED_NON_EMPTY", REQUIRED_NON_EMPTY); // Must be set and not empty
123+
await initVariable("OPTIONAL_NON_EMPTY", OPTIONAL_NON_EMPTY); // Can be undefined or non-empty
124+
```
125+
97126
## 🚀 Deployment Options
98127

99128
Due to Envar's flexible source system, you have multiple options for deploying your application. We'll demonstrate these with a Docker Compose configuration, but the same principles apply to other deployment methods as well.

0 commit comments

Comments
 (0)