1.0.5 • Published 7 years ago

@jkempema/configuration v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
7 years ago

configuration

Library to provide a consistent way of getting and setting configuration values.

Usage

Load Values

import Configuration from 'configuration'

const config = new Configuration();

config.load( {
    something: 'some value',
    somethingElse: "some other value"
} );

const something = config.get( 'something' );
const somethingElse = config.get( 'somethingElse' );

Set & Get Values

import Configuration from 'configuration'

const config = new Configuration();

config.set( 'something', 'some value' );

const something = config.get( 'something' );

const somethingElse = config.get( 'somethingElse', 'default value' );

Listen for Changes

import Configuration from 'configuration'

const config = new Configuration();

const removeEventListener = config.addEventListener( 'change', ( key ) => {
    console.log( `config key ${ key } changed to ${ config.get( key ) }` ); 
} );

config.set( 'something', 'some value' );

removeEventListener();

Global Configuration

The Configuration class has a global property to provide a means where configuration settings can accessed across libraries.

import Configuration from 'configuration'

const globalConfig = Configuration.global;

const something = globalConfig.getValue( 'something' );