typebox-env
v1.0.1
Published
Validate and Parse your environment variables with TypeBox
Downloads
201
Readme
typebox-env
Validate and Parse your environment variables with TypeBox.
Install
$ npm install typebox-env @sinclair/typebox
Usage
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. 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.
License
MIT © 2024 Martin Acosta