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

@iteam/config

Package Overview
Dependencies
Maintainers
7
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iteam/config

This is useful for when the environment-variables need to be nested and still be camel cased.

  • 12.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
7
Created
Source

config

This is useful for when the environment-variables need to be nested and
still be camel cased.

The order of how the config is beeing transformed is:

  • 0: defaults
  • 1: environment
  • 2: config-file
  • 3: secrets

So that means that environment-variables will override defaults,
and the config-file will override environment-variables and so on.

Properties defined in defaults will almost always be returned, but overridden.

For example:

  defaults: {
    foo: {
      bar: 'baz',
    }
  }

// application started with:
// FOO__SOMETHING=else npm start

console.log(config.get('foo')) // > { bar: 'baz', something: 'else' }
console.log(config.get('foo:bar')) // > 'baz'
console.log(config.get('foo:something')) // > 'else'

Types defined in defaults will be applied to overridden values:

// contents of config.json
{
  "another": [{
    "key": "not hello",
    "value": "2",
  }]
}
const options = {
  file: `${__dirname}/../config.json`,
  defaults: {
    some: {
      nested: {
        array: [ 1, 2, 3 ],
      }
    },
    booleanValues: {
      zero: false,
      one: true
    },
    another: [{
      key: 'hello',
      value: 1,
    }],
  }
}

// ...

// application started with:
// SOME__NESTED__ARRAY="4,5,6" BOOLEAN_VALUES__ZERO="true" BOOLEAN_VALUES__ONE="0"
config.get('some') // > { nested: { array: [ 4, 5, 6 ] } }
config.get('some:nested') // > { array: [ 4, 5, 6 ] }
config.get('some:nested:array') // > [ 4, 5, 6 ]
config.get('booleanValues') // { zero: true, one: false }
config.get('booleanValues:zero') // true
config.get('booleanValues:one') // false
config.get('another') // [{ key: 'not hello', value: 2 }]

The casing is always ignored as an input, but the values fetched will always be camel-cased.

For example (starting application in shell):

SOME__NESTED__CONFIG__IN_CAMEL_CASE=ok \
some__nested__secondValue=bar \
npm start # or whichever entrypoint

... will be be transformed into (result in javascript):

{
  some: {
    nested: {
      config: {
        inCamelCase: 'ok',
      },
      secondValue: 'bar',
    }
  }
}

simple usage

const config = require('@iteam/config')({
  file: `${__dirname}/../config.json`,
  defaults: {
    foo: {
      bar: 'baz',
    },
    baz: [ 1, 2, 3 ],
  }
})

// `config` also has a _getter_ for `defaults`
// this will override the previous defaults
config.defaults = { foo: { bar: 'baz' }, baz: [ 1, 2, 3 ] }

console.log(config.get('foo')) // > { bar: 'baz' }
console.log(config.get('foo:bar')) // > 'baz'
console.log(config.get('baz')) // > [ 1, 2, 3 ]

defaults can be passed to the initial function-call

const config = require('@iteam/config')({
  defaults: {
    foo: {
      bar: 'bar'
    },
    baz: 'results'
  }
})

"secrets"

This module got extended with docker-swarm in mind, and their way of handling
secrects (which is run-time mounted files).

There's a option for the config-module to look into a directory and treat all
files a key/value config.

For example: The directory /run/secrets has these file in it:

some_nested__file
some_nested__other_file

When they are provided to the module they will be transformed as such:

{
  someNested: {
    file: 'contents of "/run/secrets/some_nested__file"',
    otherFile: 'contents of "/run/secrets/some_nested__other_file"'
  }
}

To enable this, provide secrets as a argument when calling the module:

const config = require('@iteam/config')({
  secrets: {
    dir: '/run/secrets/'
  }
})

// `config` also has a _getter_ for `secrets`:
config.secrets = {
  dir: '/run/secrets/'
}

arguments:

  • defaults takes an object
{
  search: boolean // default: 'false'
  dir: string     // default: '../'
  file: string    // default: 'config.json'
}
  • secrets takes an object or a string

    When providing a string, this should be the directory where secrets are stored.
    The options-objects takes two properties:

{
  dir: string       // default: '/run/secrets/'
  separator: string // default: '__'
}
  • env takes an object
{
  separator: string // default: '__'
}
  • file takes an object or a string

    When providing a string, this should point to the full location of the config-file, or the dir will be de default

{
  search: boolean // default: false
  dir: string     // default: '../'
  file: string    // default: 'config.json'
}

FAQs

Package last updated on 29 Jun 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