# hyper-config

> Config wrapper with merge, references, string macros, tagging, yml and json file loading, environment support

Latest version **0.1.20** (published 2014-11-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install hyper-config
pnpm add hyper-config
yarn add hyper-config
bun add hyper-config
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.20 |
| Published | 2014-11-14 |
| First published | 2014-10-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Stefan Zerkalica |
| Maintainers | zerkalica |
| Keywords | config, json, merge, environment, tags |

## Links

- npm: https://www.npmjs.com/package/hyper-config
- Repository: https://github.com/zerkalica/hyper-config
- Issues: https://github.com/zerkalica/hyper-config/issues
- npm.io page: https://npm.io/package/hyper-config

## Dependencies (1)

- [traverse](https://npm.io/package/traverse.md) ^0.6.6

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.1.20 (latest) — 2014-11-14
- 0.1.19 — 2014-11-13
- 0.1.18 — 2014-11-13
- 0.1.17 — 2014-11-13
- 0.1.16 — 2014-11-10
- 0.1.15 — 2014-11-09
- 0.1.14 — 2014-11-06
- 0.1.13 — 2014-10-31
- 0.1.12 — 2014-10-30
- 0.1.11 — 2014-10-29
- 0.0.10 — 2014-10-27
- 0.0.9 — 2014-10-26
- 0.0.8 — 2014-10-25
- 0.0.7 — 2014-10-25
- 0.0.6 — 2014-10-25
- … 5 more at https://npm.io/package/hyper-config/versions

## README

# Hyper config

Config wrapper with merging, references, string macros, tagging, etc.

``` javascript
var HyperConfig = require('hyper-config');
```

## Api

* HyperConfig(object):
  * refLabel: string, '~' - reference label to config parts
  * annotationLabel: string, '@' - annotation label, mark control config parts
  * macroBegin: string, '{' - used in macro string replacement
  * macroEnd: string, '}' - used in macro string replacement

* addConfig(object): deep merge js object to config
* build(): build config and return config session object:
  * get(string): get config part by dot-separated path string or undefined if wrong path
  * getByTag(string): return array with config parts, marked by tag

## Overview
* ~<path> - link to parts of config
* ~{path} - replacement macro string
* ~disable - command to delete this config object branch
* @tag - array of tag names, group by provided tag names

```json
"section": {
  "subsection": {
    "value": "test"
  },
  "name1": {
    "value": 123,
    "param": "~{section.subsection.value}/qweqwe",
    "param2": "~~test/~~{section.subsection.value}",
    "@tag": ["tag1", "tag2"]
  },
  "name2": {
    "ref": "~section.name1"
  },
  "name3": {
    "val": "test"
  }
},

"section2.subsection2.name1": {
  "value": "example"
}
```

```js
//init.js
var Config = HyperConfig().addConfig(require('./config.json'));

Config.addConfig({
  section: {
    name3: '~disable'
  }
});

var config = Config.build();

console.log(config.get('section.subsection')); //{value: 'test'}
console.log(config.get('section.subsection.qweiweruhwitur')); // undefined
console.log(config.get('section2.subsection2.name1.value')); // example
console.log(config.get('section.name1.param')); // test/qweqwe
console.log(config.get('section.name1.param2')); // ~test/~{section.subsection.value}
console.log(config.get('section.name2.ref')); // {value: 123, param: 'test/qweqwe'}
console.log(config.get('section.name3')); // undefined
console.log(config.getByTag('tag1')); // [{value: 123, param: 'test/qweqwe'}]
```

## Merge configs

```javascript
var HyperConfig = require('hyper-config');

var defaultConfig = {
  logger: {
    transports: {
      console: {
        proc: 'console.log'
      },
      file: {
        fileName: 'test'
      }
    }
  }
};
var envConfig = {};
if (process.env.NODE_ENV === 'development') {
  envConfig = {
    logger: {
      file: {
        fileName: 'test-dev'
      }
    }
  };
}

var someConfig = {
  'logger.transports.file.fileName': 'test-some'
};
// expands to {logger: {transports: { file: {fileName: 'test'}}}}

var config = HyperConfig()
  .addConfig(defaultConfig);
  .addConfig(envConfig)
  .addConfig(someConfig)
  .build();

console.log(config.get('logger.transports.file.fileName')); // test-some in development, test in other
console.log(config.get('wrongpath')); // undefined

```

## References and macros

```javascript
var HyperConfig = require('hyper-config');

var defaultConfig = {
  console: {
    proc: 'console.log',
    name: '~common.name',
    obj: '~common.data',
    email: '~common.name@-name@@mail.test'
  },
  common: {
    name: 'test',
    data: {
      name: 'test data'
    }
  }
};

var config = HyperConfig()
  .addConfig(defaultConfig);
  .build();

console.log(config.get('console.name')); // test
console.log(config.get('console.obj.data')); // test data
config.get('common.data').name = 'test 2 data';
console.log(config.get('console.obj.data')); // test 2 data
console.log(config.get('console.email')); // test-name@mail.test
```

## Tagging

```javascript
var HyperConfig = require('hyper-config');

var defaultConfig = {
  console: {
    proc: 'console.log',
    '@tags': ['t2', 't1']
  },
  file: {
    name: 'testfile',
    '@tags': ['t1']
  },
  some: {
    name: 'testsome'
  }
};

var config = HyperConfig()
  .addConfig(defaultConfig);
  .build();

console.log(config.getByTag('t1')); // [{proc: 'console.log'}, {name: 'testfile'}]
console.log(config.getByTag('t2')); // [{proc: 'console.log'}]
console.log(config.getByTag('someTag')); // []
```

---
_Source: https://npm.io/package/hyper-config · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
