0.3.2 • Published 3 years ago

@frenchex/config-api v0.3.2

Weekly downloads
26
License
ISC
Repository
github
Last release
3 years ago

About

Configuration API let you use Configuration Lib with your own code.

It helps create and load User-scoped, Global-scoped and Directory-scoped Configuration files.

Configuration files can be .json or .js files returning plain JSON or

Installation

npm i --save @frenchex/config-api

Usage

From File

Example loading from file (from tests) :

import * as api from "@frenchex/config-api"

const config = await api.fromFile({
    env: {env: 'dev'},
    file: path.join(testResourcesRootPath, 'js.js'),
    root: testResourcesRootPath
})

const foobar = await config.get<string>('foo.bar');
const foobar2 = await config.get<string>('foo.foobar');
const foo = await config.get<{ bar: string, foobar: string }>('foo');
const promise = await config.get<string>('promise');

expect(foobar).to.be.equal('foobar');
expect(foobar2).to.be.equal('foobarfoobar');
expect(foo).to.be.deep.equal({bar: 'foobar', foobar: 'foobarfoobar'});
expect(promise).to.be.deep.equal('resolved');

From JS object

Example loading config from object (from tests):

const config = await api.fromDeclaration({
    $: {
        foo: {
            bar: 'foobar'
        }
    }
})

const bar = await config.get<string>('foo.bar');
expect(bar).to.be.equal('foobar');

From File & JS object

You can also do both

const config = await api.fromFile({
    env: {env: 'dev'},
    file: path.join(testResourcesRootPath, 'js.js'),
    root: testResourcesRootPath,
    $: {
        "imports": ['my_file_%env%.json'],  
    }
})
0.3.2

3 years ago

0.3.1

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago