0.0.16 • Published 3 years ago

@logzio-node-toolbox/config v0.0.16

Weekly downloads
283
License
MIT
Repository
github
Last release
3 years ago

Config

an efficient config manager based on Joi schema for better easy managing configurations

Usage

import { Config } from '@logzio-node-toolbox/config';

const schema = {}; // Joi schema or array of Joi schemas (in case or array will merge the schemas)

const defaults = {}; // defaults to override the schema defaults (use to pass defaults per region or environment)

const overrides = {}; // configs that could never be override even when try to set (usually environment variables)

const config = new Config({ schema, defaults, overrides });

get value

use path to fetch nested value, if empty will fetch the all config

const value = config.get('path.to.value');

set value

use path in key property to set nested values, if empty will mergeDeep from root

onError - callback for when validation error with the schema, if onError return true will continue with the merge config even if not valid

config.set({ value: {}, key = 'path.to.set', onError: (err) => {
  console.log(err)
  return true;
} })

subscribe

onChange - callback to invoke when value changed if key is empty will watch all config

return unSubscribe method

const unSubscribe = config.subscribe({ key: 'path.to.value.to.watch', onChange: (value) => {
  console.log("new value:", value);
}})

unSubscribe(); // stop watching value
0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago