Giter VIP home page Giter VIP logo

ts-envvar's Introduction

@grzpab/ts-envvar

A library for managing environment variables in TypeScript projects.

Content

The library contains five functions, one for asserting non-nullability and four for extracting values with a specific type.

These are the following:

  • assertNonNullable,
  • extractStringEnvVar,
  • extractNumberEnvVar,
  • extractIntegerEnvVar,
  • extractBooleanEnvVar.

assertNonNullable

This function acts as a TypeScript assertion for non-nullable values:

  • if the provided value is nullable, it throws an error,
  • if the provided value is non-nullable, it asserts its type to be non-nullable.

An exemplary usage:

const { A } = process.env;

assertNonNullable('A', A);

extractStringEnvVar

This function extracts the string value of an indicated environment variable or throws an error, should the variable be not present.

An example is available below:

const A = extractStringEnvVar('A');

extractNumberEnvVar

This function extracts the value of an indicated environment variable and casts it to a number. If the variable is not present or the function cannot cast the value into a number, it will throw an error.

Check the usage below:

const A = extractNumberEnvVar('A');

extractIntegerEnvVar

This function extracts the value of an indicated environment variable and casts it to an integer. If the variable is not present or the function cannot cast the value into an integer, it will throw an error.

Check the usage below:

const A = extractIntegerEnvVar('A');

extractBooleanEnvVar

This function extracts the value of an indicated environment variable and casts it to a boolean. If the variable is not present or the function cannot cast the value into a boolean, it will throw an error.

Check the usage below:

const A = extractBooleanEnvVar('A');

ts-envvar's People

Contributors

grzpab avatar

Stargazers

Kendry Grullón avatar Charlie Martin avatar Siarhei avatar Jrson avatar

Watchers

 avatar

Forkers

kenzik mktbsh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.