parse-env-var

1.0.0 • Public • Published

parse-env-var

Usage

import {
  requiredString, 
  optionalString,
  requiredInt,
  optionalInt,
  requiredBoolean,
  optionalBoolean
} from "parse-env-var";

process.env["STRING_VAR"] = "foo";
process.env["INT_VAR"] = "123";
process.env["BOOL_VAR"] = "true";

const optionalStringVar = requiredString("STRING_VAR"); // "foo"
const optionalStringVar = optionalString("NOT_SET");    // undefined
const requiredStringVar = requiredString("STRING_VAR"); // "foo"
const requiredStringVar = requiredString("NOT_SET");    // throws "Missing required environment variable: NOT_SET"

const optionalIntVar = optionalInt("INT_VAR");          // 123
const optionalIntVar = optionalInt("NOT_SET");          // undefined
const requiredIntVar = requiredInt("INT_VAR");          // 123
const requiredIntVar = requiredInt("NOT_SET");          // throws "Missing required environment variable: NOT_SET"

const optionalBooleanVar = optionalBoolean("BOOL_VAR"); // true
const optionalBooleanVar = optionalBoolean("NOT_SET");  // undefined
const requiredBooleanVar = requiredBoolean("BOOL_VAR"); // true
const requiredBooleanVar = requiredBoolean("NOT_SET");  // throws "Missing required environment variable: NOT_SET"

Booleans

"true", "TRUE", "True", "1" are all considered true for boolean variables.
"false", "FALSE", "False", "0" are all considered false for boolean variables.

Readme

Keywords

none

Package Sidebar

Install

npm i parse-env-var

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

4.66 kB

Total Files

15

Last publish

Collaborators

  • bconnorwhite