Socket
Socket
Sign inDemoInstall

@unifig/env

Package Overview
Dependencies
27
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @unifig/env

Environmental variables adapter for unifig


Version published
Maintainers
1
Created

Changelog

Source

0.7.0 (2023-01-02)

Features

  • core: changed validation errors from POJOs to classes (957330c)
  • core: compatibility with new versions of class-transformer (689e26b)
  • core: new registration variations (657220f)
  • core: validator rework (acf2baf)
  • env: adjusted to new ConfigAdapter interface (46593b4)
  • nest: adjusted to new ConfigContainer interface (d729e93)
  • validation-presenter-table: package release (ce81cb3)

Performance Improvements

  • nest: used Symbols for injection tokens (7fca521)

BREAKING CHANGES

  • core: Added new variation of register method - registerOrReject. Second one continues the current behavior whereas register returns validation exception or undefined in plac of throwing it.
  • core: Rich validation report was removed from the exception itself and rich object containing abstract report was added in it's place. Register method doesn't throw validation exception and returns it if one occurs. To utilize previous behavior use registerOrReject method.

Readme

Source

Env variables & files adapter for Unifig

Table of contents

Installation

npm i @unifig/env
# or
yarn add @unifig/env

Quick Start

# .env
PORT=3000
export class DbSettings {
  @From('DB_URL')
  @IsString()
  url: string;

  @From('DB_PASSWORD')
  @IsString()
  password: string;
}

export class Settings {
  @From('PORT')
  @IsInt()
  port: number;

  @Nested(() => DbSettings)
  @IsDefined()
  db: DbSettings;
}
import { Config } from '@unifig/core';
import { EnvConfigAdapter } from '@unifig/env';

async function bootstrap() {
  await Config.register({
    template: Settings,
    adapter: new EnvConfigAdapter(),
  });

  console.log(Config.get(Settings).port); // output: 3000
}

bootstrap();

Properties Mapping

Environment variables are mapped to 1D dictionary.

# .env
PORT=3000
DB_HOST=localhost
DB_PORT=4588
// adapter output
{
  PORT: 3000,
  DB_HOST: 'localhost',
  DB_PORT: 4588
}

Options

PropertyWhat it doesRequired
envFilesPathsPath to optional environment files to be loaded in given order. Values from them will be overwritten by process envs.×
ignoreEnvVarsIf "true", environment variables will not be loaded.×
expandVariablesSee https://www.npmjs.com/package/dotenv-expand.×

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

FAQs

Last updated on 02 Jan 2023

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc