composable-config
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Composable Config

Composable app configuration with loading, conversion, validation and type support built-in.

Quick Start

npm i composable-config
import { createConfig, buildConfig } from 'composable-config';
import * as ct from 'composable-config/io';
import envLoader from 'composable-config/loaders/env';

const dbConfig = createConfig({
  tableName: ct.string,
});

const serverConfig = createConfig({
  host: {
    _: ct.string,
    default: '127.0.0.1',
  },
  port: {
    _: ct.Port,
    default: 8080,
    env: 'SERVER_PORT',
  },
});

const appConfig = createConfig({
  server: serverConfig,
  db: dbConfig,
});

const config = buildConfig({
  config: appConfig,
  loaders: [envLoader()],
  defaults: {
    db: {
      tableName: 'xyz',
    },
  },
});

assert(process.env['SERVER_PORT']).equals('1234');

assert(config).equals({
  db: {
    tableName: 'xyz',
  },
  server: {
    host: '127.0.0.1',
    port: 1234,
  },
});

/composable-config/

    Package Sidebar

    Install

    npm i composable-config

    Weekly Downloads

    1

    Version

    0.2.0

    License

    MIT

    Unpacked Size

    80.7 kB

    Total Files

    81

    Last publish

    Collaborators

    • jakzo