https://github.com/tinchoz49/typebox-env
Validate and Parse your environment variables with TypeBox.
https://github.com/tinchoz49/typebox-env
environment environment-variables parse typebox validate
Last synced: 4 months ago
JSON representation
Validate and Parse your environment variables with TypeBox.
- Host: GitHub
- URL: https://github.com/tinchoz49/typebox-env
- Owner: tinchoz49
- License: mit
- Created: 2024-10-02T13:28:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-12T17:03:40.000Z (about 1 year ago)
- Last Synced: 2025-10-01T21:23:24.058Z (9 months ago)
- Topics: environment, environment-variables, parse, typebox, validate
- Language: TypeScript
- Homepage:
- Size: 193 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# typebox-env
> Validate and Parse your environment variables with TypeBox.

[](https://github.com/tinchoz49/eslint-config-standard-ext)
[](https://github.com/RichardLitt/standard-readme)
## Install
```bash
$ npm install typebox-env @sinclair/typebox
```
## Usage
```ts
import { Type } from '@sinclair/typebox'
import { JSON, parseEnv, SplitArray } from 'typebox-env'
const schema = Type.Object({
FOO_BAR: SplitArray(Type.String()),
BAZ: Type.String(),
JSON: JSON(Type.Object({
foo: Type.String(),
bar: Type.String(),
})),
DEEP: Type.Object({
NESTED: Type.Object({
FOO: Type.String(),
}),
BAR: Type.String(),
}),
})
const env = {
FOO_BAR: 'a,b,c',
BAZ: 'qux',
JSON: '{"foo":"bar","bar":"baz"}',
DEEP_NESTED_FOO: 'qux',
DEEP_BAR: 'baz',
}
const result = parseEnv(schema, env)
console.log(result)
/*
{
FOO_BAR: ['a', 'b', 'c'],
BAZ: 'qux',
JSON: {
foo: 'bar',
bar: 'baz',
},
DEEP: {
NESTED: {
FOO: 'qux',
},
BAR: 'baz',
},
}
*/
```
## Issues
:bug: If you found an issue we encourage you to report it on [github](https://github.com/tinchoz49/typebox-env/issues). Please specify your OS and the actions to reproduce it.
## Contributing
:busts_in_silhouette: Ideas and contributions to the project are welcome. You must follow this [guideline](https://github.com/tinchoz49/typebox-env/blob/main/CONTRIBUTING.md).
## License
MIT © 2024 Martin Acosta