Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

envoose

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

envoose

Simplistic env var parser inspired by mongoose schema

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Envoose

npm version Build Status Coverage Status Dependencies Dev Dependencies

Simplistic env var parser inspired by mongoose schema

Install

# Using npm
$ npm install envoose

# Or using yarn
$ yarn add envoose

Example

// config.js
const envoose = require('envoose')

const configSchema = {
  MONGO_URI: { required: true },
  REQUEST_TIMEOUT: { type: Number, default: 1000 },
  EXPIRY_DATE: { type: Date },
  BOOLEAN_VAL: { type: Boolean },
  CUSTOM_VAR: { env: 'CUSTOM_ENV_VAR' },
  LIST: { type: s => s.split(',').map(Number) },
  ENUM_VALID: { type: String, enum: ['A', 'B', 'C'] },
  MATCH_VALID: { type: String, match: /.*match.*/g },
  CUSTOM_VALID: { type: Number, validator: x => x !== 10 }
  // INVALID_MIX: { required: true, default: 10 }
}

const config = envoose.getConfig(configSchema)

module.exports = config

Docs

envoose.getConfig(configSchema)

Validate and load configs object using configSchema

ConfigSchema

A configSchema is an object that tells envoose which env vars to load and how to load them, in its most basic form, it's just a set of keys to load

const configSchema = {
  FIRST_KEY: {},
  SECOND_KEY: {}
}
Options
required

A required key must be supplied through env vars. If the value is not available in process.env, getConfig will throw ConfigValidationError.

Note that default and required can't be combined.

default

A value to fallback to if the env var is not set.

env

By default the config is read from env var with the same name as the config name. If env is supplied, it will read from that env var instead.

type

Env vars are strings by default, however envoose allows you to cast them to different data types.

Supported Types
  • String (default)
  • Number
  • Date
  • Boolean ('true', 'yes', '1' evaluate to true, while 'false', 'no', '0' evaluate to false, CastError will be thrown otherwise)
  • Custom types by supplying a mapping function (ex: array of numbers s => s.split(',').map(Number))
enum

Built in validator that checks whether the value falls in one of the values in the list. Throws ConfigValidationError if not found in enum.

match

Built in validator that checks whether the value matches this regex or not. Throws ConfigValidationError if not matched.

validator

Accepts custom validation function that should return true if valid and false otherwise.

Keywords

FAQs

Package last updated on 08 Aug 2019

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc