typebox-env
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

typebox-env

Validate and Parse your environment variables with TypeBox.

Tests JavaScript Style Guide standard-readme compliant

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

🐛 If you found an issue we encourage you to report it on github. Please specify your OS and the actions to reproduce it.

Contributing

👥 Ideas and contributions to the project are welcome. You must follow this guideline.

License

MIT © 2024 Martin Acosta

Readme

Keywords

Package Sidebar

Install

npm i typebox-env

Weekly Downloads

48

Version

2.0.1

License

MIT

Unpacked Size

15.5 kB

Total Files

8

Last publish

Collaborators

  • tinchoz49