Socket
Book a DemoInstallSign in
Socket

@stefanoruth/env

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stefanoruth/env

[![Build & Tests](https://github.com/stefanoruth/env/actions/workflows/build.yml/badge.svg)](https://github.com/stefanoruth/env/actions/workflows/build.yml)

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

Typescript Env Parser

Build & Tests

A typescript env parser, that validates server configuration and works well integration with libraries such as dotenv

Installation

yarn add @stefanoruth/env

Example

import { envParser } from '@stefanoruth/env'

const config = envParser({
    port: { type: 'number', defaultValue: 3000, env: 'PORT' },
    domain: { type: 'string', env: 'DOMAIN' },
    secret: { type: 'string', env: 'JWT_SECRET', optional: true },
    mode: { type: 'const', options: ['development', 'production'] as const, env: 'NODE_ENV' },
})

config.port // number
config.domain // string
config.secret // string | undefined
config.mode // 'development' | 'production'

Documentation

Supported types

TypeNotes
number
string
boolean
constConst takes in an array of allowed values, the system with throw errors if the value from runtime or default value has not been set, (Note the return will be strict if you cast the array as const else, the array will be treated as an array of strings)

Each type has a the options:

OptionDescription
envDetermines which key should be used when extracting the value from process.env
optionalIf a value is not marked as optional the system will automaticly throw an error when being called
defaultValueEach type has a default value that relates to the chosen type

Keywords

typescript

FAQs

Package last updated on 09 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts