@ts-awesome/config
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@ts-awesome/config

Typescript friendly wrapper library over config.

Please check their documentation for all the details about configuration files here

We also get some spice from @ts-awesome/model-reader

Basic use cases

import {Config} from '@ts-awesome/config';

const config = new Config();

// reads optional config property `some.value` and makes sure it is actually string
const someValue = config.get('some.value', String, true);

// reads required config property `some.number` and makes sure it is actually number
// also throws ConfigError is value is missing
const someNumeric = config.get('some.number', Number);

Advanced example

import {Config} from '@ts-awesome/config';
import {readable} from "@ts-awesome/model-reader";

// lets declare config model
class SomeConfig {
  @readable
  public readonly host!: string;
  @readable
  public readonly username!: string;
  @readable
  public readonly password!: string;
  @readable(Boolean, true)
  public readonly secure!: true | null; 
}

const config = new Config();

// reads required configuration model based on SomeConfig declarations, 
// throws errors if configuration is invalid
const someConfig = config.get('some.cofing', SomeConfig);

// someConfig is instance of SomeConfig

Custom config driver

Config class excepts a compatible config driver as first optional argument. Config driver should respect ConfigDriver type. Please check src/interfaces.ts for more details

License

May be freely distributed under the MIT license.

Copyright (c) 2022 Volodymyr Iatsyshyn and other contributors

Readme

Keywords

none

Package Sidebar

Install

npm i @ts-awesome/config

Weekly Downloads

90

Version

1.0.1

License

MIT

Unpacked Size

12.4 kB

Total Files

18

Last publish

Collaborators

  • ts-awesome-bot
  • viatsyshyn