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

@dmcquay/typed-config

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dmcquay/typed-config

Validate your config. Make TypeScript aware of the resulting types.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

typed-config is a very simple and opinionated library for getting config values from the environment in TypeScript. The design goals are:

  • Get config values from process.env
  • Validate them and provide useful error messages
  • Return the values with meaningful types

@dmcquay/typed-config usage example

Install

npm install -S @dmcquay/typed-config

Example usage

You might create a file called config.ts with the following contents.

import typedConfig from '@dmcquay/typed-config'

const config = typedConfig()

export default {
    apiBaseUrl: config.getString('API_BASE_URL', {pattern: /^https?:\/\/\w+$/}),
    enableFeatureX: config.getBoolean('ENABLE_FEATURE_X', false),
    isDev: config.getBoolean('IS_DEV'),
    maxWidgetCount: config.getInteger('MAX_WIDGET_COUNT')
}

API

function getString(key: string, opts: StringOptions = {}): string
function getNumber(key: string, opts: NumberOptions = {}): number
function getInteger(key: string, opts: NumberOptions = {}): number
function getBoolean(key: string, defaultValue?: boolean): boolean

interface IStringOptions {
    pattern?: RegExp
}

interface INumberOptions {
    maxValue?: number,
    minValue?: number
}

FAQs

Package last updated on 23 Oct 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