ntreeconfig

Configuration file with multiple inheritance of group properties and using relative Unix paths

Usage no npm install needed!

<script type="module">
  import ntreeconfig from 'https://cdn.skypack.dev/ntreeconfig';
</script>

README

NTreeConfig

Configuration file with multiple inheritance of group properties and using relative Unix paths

Quick Start

$ npm install ntreeconfig
$ cd node_modules/ntreeconfig
$ npm install
$ npm test

Example

File "config1.json":

{
  postgres: {
    main: {
      port: 123,
      user: "user1",
      password: "pass1",
      key4: 4
    },
    local: {
      inherit: "../main",
      host: "localhost",
      database: "db1"
    },
    remote: {
      inherit: "../main",
      database: "db2",
      key3: 3
    },
    pc3: {
      inherit: "../remote",
      host: "ip2",
      key1: 1
    }
  },
  pc3: {
    inherit: ["..//postgres/pc3"],
    key0: 0
  }
}

Using the file "config1.json":

import { loadConfig } from "ntreeconfig";

//...
const config = await loadConfig("config1.json");

config.getValue("/postgres/pc3/port"); // -> 123
config.getValue("pc3/port"); // -> 123

config.getObject("pc3");
// -> 
{
  key0: 0,
  host: 'ip2',
  key1: 1,
  database: 'db2',
  key3: 3,
  port: 123,
  user: 'user1',
  password: 'pass1',
  key4: 4
}

API

import { loadConfig } from "ntreeconfig";

function loadConfig(fileName: string, pathBase?: OneOrArray<string>): Promise<NTreeConfig>;

NTreeConfig:getValue(keys: PathUnix | OneOrArray<ObjectKeyType>, valueDefault?: any): any;
NTreeConfig:getObject(keys: OneOrArray<ObjectKeyType>): object;

Advanced

Full config file (*.json)

Full module tests (*.ts)