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

1.65.4 • Public • Published

Config

Application configurator

Examples:

Get:

import { Config } from '@biorate/config';

export const data = {
  a: {
    b: {
      c: 1,
      d: 2,
    },
  },
  b: 'world!',
  c: { d: 'Hello ${b}' },
  d: '${c.d} Repeat for all ${b}',
};

const config = new Config(data);

console.log(config.get('a')); // { b: { c: 1, d: 2 } }
console.log(config.get('a.b')); // { c: 1, d: 2 }
console.log(config.get('b')); // world!
console.log(config.get('c')); // { d: 'Hello world!' }
console.log(config.get('c.d')); // 'Hello world!'
console.log(config.get('d')); // Hello world! Repeat for all world!

Set:

import { Config } from '@biorate/config';

const config = new Config();

config.set('a', 1);

console.log(config.get('a')); // 1

Has:

import { Config } from '@biorate/config';

const config = new Config();

config.set('a', 1);

console.log(config.has('a')); // true
console.log(config.has('b')); // false

Merge:

import { Config } from '@biorate/config';

const config = new Config();

config.merge({
  a: { b: { c: 1 } },
});

config.merge({
  a: { b: { d: 2 } },
});

console.log(config.has('a')); // true
console.log(config.has('a.b')); // true
console.log(config.get('a.b.c')); // 1
console.log(config.get('a.b.d')); // 2

Learn

  • Documentation can be found here - docs.

Release History

See the CHANGELOG

License

MIT

Copyright (c) 2021-present Leonid Levkin (llevkin)

Readme

Keywords

none

Package Sidebar

Install

npm i @biorate/config

Weekly Downloads

11

Version

1.65.4

License

MIT

Unpacked Size

185 kB

Total Files

38

Last publish

Collaborators

  • llevkin