1.120.0 • Published 7 months ago

@biorate/config v1.120.0

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

Config

Application configurator

Examples:

Get / Set:

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

const config = new Config();

config.set('a', 1);

console.log(config.get<number>('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<number>('a.b.c')); // 1
console.log(config.get<number>('a.b.d')); // 2

String template:

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

const config = new Config();

config.merge({
  url: '${protocol}${host}/${path}',
  protocol: 'https://',
  host: 'hostname.ru',
  path: 'main',
});

console.log(config.get<string>('url')); // https://hostname.ru/main

Link template:

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

const config = new Config();

config.merge({
  obj1: { a: 1, b: 2 },
  obj2: '#{obj1}',
});

console.log(config.get<{ a: number; b: number }>('obj2')); // { "a": 1, "b": 2 }

RegExp template:

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

const config = new Config();

config.merge({
  regexp: 'R{/^test$/igm}',
});

const regexp = config.get<RegExp>('regexp');

console.log(regexp.test('test')); // true

Function template:

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

const config = new Config();

config.merge({
  sum: 'F{a, b => return a + b;}',
});

const sum = config.get<(a: number, b: number) => number>('sum');

console.log(sum(1, 2)); // 3

Empty template:

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

const config = new Config();

config.merge({ data: '!{object}' });
console.log(config.get('data')); // {}

config.merge({ data: '!{array}' });
console.log(config.get('data')); // []

config.merge({ data: '!{void}' });
console.log(config.get('data')); // undefined

config.merge({ data: '!{null}' });
console.log(config.get('data')); // null

config.merge({ data: '!{string}' });
console.log(config.get('data')); // ""

config.merge({ data: '!{ }' });
console.log(config.get('data')); // null

If you want to disable templates, you can turn off it in static Config.Template variable:

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

Config.Template.string = false;
Config.Template.empty = false;
Config.Template.regexp = false;
Config.Template.function = false;
Config.Template.link = false;

Learn

  • Documentation can be found here - docs.

Release History

See the CHANGELOG

License

MIT

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

1.96.0

11 months ago

1.90.0

12 months ago

1.120.0

7 months ago

1.95.1

11 months ago

1.91.5

12 months ago

1.95.0

11 months ago

1.91.4

12 months ago

1.93.1

11 months ago

1.91.3

12 months ago

1.93.0

11 months ago

1.91.2

12 months ago

1.91.1

12 months ago

1.91.0

12 months ago

1.100.0

9 months ago

1.104.0

9 months ago

1.102.0

9 months ago

1.102.1

9 months ago

1.76.3

1 year ago

1.65.4

2 years ago

1.54.0

2 years ago

1.42.2

2 years ago

1.42.1

2 years ago

1.38.2

2 years ago

1.38.3

2 years ago

1.38.1

2 years ago

1.38.4

2 years ago

1.30.12

2 years ago

1.29.0

3 years ago

1.28.1

3 years ago

1.28.0

3 years ago

1.26.0

3 years ago

1.27.2

3 years ago

1.27.0

3 years ago

1.27.1

3 years ago

1.24.0

3 years ago

1.11.2

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.0.0

3 years ago

1.4.0

3 years ago

1.2.2

3 years ago

0.30.9

3 years ago

0.30.7

3 years ago

0.30.6

3 years ago

0.30.5

3 years ago

0.30.11

3 years ago

0.30.2

3 years ago

0.30.0

3 years ago

0.30.19

3 years ago

0.29.1

3 years ago

0.28.0

4 years ago

0.27.0

4 years ago

0.26.0

4 years ago

0.25.0

4 years ago

0.21.0

4 years ago

0.20.0

4 years ago

0.19.0

4 years ago

0.18.2

4 years ago

0.23.0

4 years ago

0.22.0

4 years ago

0.12.0

4 years ago

0.13.0

4 years ago

0.12.1

4 years ago

0.14.0

4 years ago

0.12.2

4 years ago

0.15.0

4 years ago

0.12.3

4 years ago

0.12.4

4 years ago

0.16.1

4 years ago

0.18.0

4 years ago

0.17.1

4 years ago

0.11.0

4 years ago

0.11.1

4 years ago

0.10.1

4 years ago

0.10.2

4 years ago

0.10.0

4 years ago