2.0.0 • Published 2 years ago

yup-env v2.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
2 years ago

yup-env

CircleCI npm version Known Vulnerabilities

NPM

This is simple library to parse and validate environment variables using yup with full TypeScript support.

:zap: Want more complex configuration solution? Try confres :zap:

Installation

You can get latest release with type definitions from NPM:

npm install yup yup-env --save

Usage

Very basic usage:

// examples/simple.ts
import * as yup from 'yup'
import yupEnv from 'yup-env'

// define object schema that describes your app config
const schema = yup.object()
  .noUnknown()
  .shape({
    nodeEnv: yup.string().oneOf(['development', 'production']).default('production'),
    port:    yup.number().default(3000),
  })

// parse and validate environment variables
const config = yupEnv({ schema })

console.log(config)
// { port: 3000, nodeEnv: 'production' }

// if you specify following environment variables:
//   NODE_ENV=development
//   PORT=3001
// the output would be: { port: 3001, nodeEnv: 'development' }

More examples in examples directory.

API

The library exposes single function as default export with following signature

function yupEnv<TSchema extends yup.AnyObjectSchema>(options: Options<TSchema>): yup.Asserts<TSchema>; 

The function accepts following options:

NameTypeDescriptionRequiredDefault value
schemayup.ObjectSchemaObject schema used to cast and validate environment variables.:heavy_check_mark:
envRecord<string, string>Environment variables to process.value of process.env
prefixstringPrefix of environment variables names to process.'' (empty string)
levelSeparatorstringNested structures path separator.__
validateValidateOptionsYup scheme validate options.
keyNamingStrategyKeyNamingStrategyKey naming strategy.KeyNamingStrategy.camelCase
2.0.0-beta.1

2 years ago

2.0.0

2 years ago

1.2.1

2 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago