# crampon

> Hierarchical configuration, made easy.

Latest version **1.0.0** (published 2016-05-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install crampon
pnpm add crampon
yarn add crampon
bun add crampon
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-05-13 |
| First published | 2014-01-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Matt Dunlap |
| Maintainers | prestaul |
| Keywords | config, configuration, environment, hierarchy, settings |

## Links

- npm: https://www.npmjs.com/package/crampon
- Repository: https://github.com/Prestaul/crampon
- Homepage: https://github.com/Prestaul/crampon#readme
- Issues: https://github.com/Prestaul/crampon/issues
- npm.io page: https://npm.io/package/crampon

## Dependencies (1)

- [deap](https://npm.io/package/deap.md) ^1.0.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-05-13
- 0.2.2 — 2015-04-08
- 0.2.1 — 2014-04-10
- 0.2.0 — 2014-04-10
- 0.1.2 — 2014-01-21

## README

crampon
=======

Hierarchical configuration, made easy.


Basic Usage (No Hierarchy)
--------------------------
In it's most basic usage, you can add configuration objects to a crampon instance and then access that configuration:
```js
var Crampon = require('crampon'),
    crampon = new Crampon().add({
        root: '/home/apps/ftknox'
    });

var config = crampon.getConfig();
```


### Adding Data
Data can be added using the `add` and `addFile` methods. New data is merged with old data and if there are conflicts then new values will take precedence:
```js
var crampon = new Crampon().add({
        root: '/home/apps/ftknox',
        db: {
            name: 'ftknox',
            pwd: '1234'
        }
    })
    .addFile('./conf'); // could be conf.js or conf.json if extension is not specified

// conf.js: module.exports = { db: { pwd:'abcd' } };

assert.deepEqual(crampon.getConfig(), {
    root: '/home/apps/ftknox',
    db: {
        name: 'ftknox',
        pwd: 'abcd'
    }
});
```


Hierarchical Configuration
--------------------------
Hierarchical configuration can be used to setup environment specific configuration with the ability to inherit and override configuration for each environment:
```js
// Set the hierarchy when constructing an instance of crampon
var crampon = new Crampon(['prod', 'test', 'dev']).add({
    prod: {
        root: '/home/apps/ftknox',
        db: {
            name: 'ftknox',
            pwd: '1234'
        },
        debugLevel: 3
    },
    stage: {
        debugLevel: 2
    },
    dev: {
        db: {
            name: 'ftknox_dev'
        },
        debugLevel: 1
    }
});

// Get the dev configuration
var config = crampon.getConfig('dev');

// Note that the environment param defaults to the NODE_ENV environment variable

assert.deepEqual(config, {
    root: '/home/apps/ftknox',
    db: {
        name: 'ftknox_dev',
        pwd: '1234'
    },
    debugLevel: 3
});
```

### Overrides
When using a hierarchical configuration, data added via `add` and `addFile` must have environment keys at the root.
In order to override environment specific configuration with configuration that applies in all cases you can use `addOverride` and `addOverrideFile`.

Continuing the above example, you could override the debugLevel in your dev environment in this way:
```js
crampon.addOverride({
    debugLevel: 1
});

// Get the configuration
var config = crampon.getConfig('dev');

// debugLevel is now 1 in all environments
assert.deepEqual(config, {
    root: '/home/apps/ftknox',
    db: {
        name: 'ftknox_dev',
        pwd: '1234'
    },
    debugLevel: 1
});
```

### Arrays
As of version 0.2, arrays in configuration are replaced, rather than merged.

```js
var crampon = new Crampon().add({
        favoriteColor: 'pink',
        otherColors: [
            'blue',
            'red'
        ]
    })
    .add({
        otherColors: [
            'green',
            'black'
        ]
    });

assert.deepEqual(crampon.getConfig(), {
    favoriteColor: 'pink',
    otherColors: [
        'green',
        'black'
    ]
});
```

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