Class Config

Hierarchy

Implements

Constructors

Properties

Methods

Constructors

Properties

data: {} = {}

Type declaration

    Description

    Data storage

    Methods

    • Type Parameters

      • T = unknown

      Parameters

      • path: PropertyPath

        data path

      • Optional def: T

        default value

        Optional

      Returns T

      Description

      Get config property by path

      Example

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

      const config = new Config();

      config.set('a', 1);

      console.log(config.get('a')); // 1
      console.log(config.get('b', 2)); // 2
      console.log(config.get('b')); // UndefinedConfigPathError: Undefined config path [b]
      // at Config.get (src/index.ts:2:1608)
      // at Context.<anonymous> (tests/index.spec.ts:19:24)
      // at processImmediate (node:internal/timers:464:21)
    • Parameters

      • path: PropertyPath

        data path

      Returns boolean

      Description

      Has config property by path

      Example

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

      const config = new Config();

      config.set('a', 1);

      console.log(config.has('a')); // true
    • Parameters

      • data: unknown

        data object

      Returns void

      Description

      Merge config data

      Example

      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
    • Parameters

      • path: PropertyPath

        data path

      • value: unknown

        data value

      Returns void

      Description

      Set config property by path

      Example

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

      const config = new Config();

      config.set('a', 1);

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

    Generated using TypeDoc