1.1.6 • Published 2 years ago

@allgemein/config v1.1.6

Weekly downloads
31
License
MIT
Repository
github
Last release
2 years ago

@allgemein/config

Build Status codecov Dependency Status

Commons-config is a configurable configuration content handler which supports multiple configuration infrastructures and file formats.

Feature:

  • Typescript support
  • Interpolation
  • Namespacing
  • Extendable by own handler or file support
  • Multiple files
  • Multiple configuration variants combination possible

File type support

Supported configuration types

System configuration

import {Config} from "commons-config";

Config.options({
    configs: [
        {
            type: 'system'
        }
    ]
})

let hostname = Config.get('os.hostname')
let stage = Config.get('env.stage')

File configuration

Sample file structure:

./config/
    default.yml
    default-devhost.yml
    default-prodhost-production.yml
    secrets-devhost.yml
    secrets-prodhost-production.yml

Sample code:

import {Config} from "commons-config";

Config.options({
    configs: [
        {
            type: 'file',
            file: {
                dirname: `./config`,
                filename: 'default'
            },
            pattern: [
                'default-${os.hostname}',
                'default-${os.hostname}-${env.stage}'
                'secrets-${os.hostname}'
            ]
        }
    ]
}

Directory configuration

Sample file structure:

./config/
    default.yml
./config/schema/
    db_access.yml
    db_access-production.yml
    db_structure.yml
./config/modules/
    module01.json
    module02.yml

Sample code:

import {Config} from "commons-config";

Config.options({
    configs: [
        {
            type: 'directory',
            dirname: './config',
            prefixing: 'by_dirname',
            suffixPattern: [
                '${env.stage}',
                '${os.hostname}',
                '${os.hostname}-${env.stage}'
            ]
        }
    ]
}

let userName = Config.get('schema.database.user')

Combinig multiple configuration types

Sample file structure:

./
    secrets.yml
    secrets-prodhost.yml
./config/
    default.yml
./config/schema/
    db_access.yml
    db_access-production.yml
    db_structure.yml
./config/modules/
    module01.json
    module02.yml

Sample file structure:

import {Config} from "commons-config";

Config.options({
    configs: [
        {
            type: 'system'
        },
        {
            type: 'file',
            file: {
                dirname: `./`,
                filename: 'default'
            },
            pattern: [
                'secrets-${os.hostname}'
            ]
        },
        {
            type: 'directory',
            dirname: './config',
            prefixing: 'by_dirname'
            suffixPattern: [
                '${env.stage}',
                '${os.hostname}',
                '${os.hostname}-${env.stage}'
            ]
        }
    ]
}

Embedding in code

Integration in javascript source code:

const commons_config = require('commons-config')
const Config = commons_config.Config

Config.options({ ... })

Integration in typescript source code:

import {Config} from "commons-config";

Config.options({ ... })

Notice

  • All enviroment variables in "env" are lower-case

Links

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago