1.1.0 • Published 4 years ago

conev-source-json v1.1.0

Weekly downloads
44
License
MIT
Repository
-
Last release
4 years ago

conev-source-json

conev-source-json is an implementation of conev's source to get configuration from json.

npm.io

Install

# with npm 
npm install conev-source-json
 
# or with Yarn 
yarn add conev-source-json

Usage

Get ConfigBuilder from conev and Sources to use.

import { ConfigBuilder } from 'conev';
import JsonSource from 'conev-source-json';

And create Source and set up.

const jsonSource = new JsonSource();

jsonSource    
	.setConfig('basic', basic) // basic is JSON
    .setConfig('dev', dev) // dev is JSON
    .setConfig('prd', prd); // prd is JSON

Create ConfigBuilder and set Environment, add source. (highest priority is added first).

const builder = new ConfigBuilder();

builder
    .setEnv('dev', 'basic')
    .addSource(jsonSource);

Build configuration

const config = await builder.build(); // This is the result of combining dev and basic.

Use configuration

config.get() // The whole configuration created comes out
config.get('a.b.c'); // Is same as config.get().a.b.c

Json Source

class JsonSource {
    constructor(map?: Map<string, object>);
    setConfig(env: string, ...values: object[]): JsonSource
    addConfig(env: string, ...values: object[]): JsonSource;
    removeConfig(env: string): JsonSource;
    export(): Promise<Map<string, object>>;
}

JsonSource defines the source from JSON. Use setConfig to add a configuration for a new environment or removeConfig to delete a configuration. Map is returned as the result value of export. The key of this map is environment and the value is the configuration when environment.

1.1.0

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago