Socket
Socket
Sign inDemoInstall

@dmcquay/typed-config

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @dmcquay/typed-config

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


Version published
Weekly downloads
12
Maintainers
1
Created
Weekly downloads
 

Readme

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

Last updated on 23 Oct 2019

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