# map-config

> Map configuration objects to application methods.

Latest version **0.5.0** (published 2016-02-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install map-config
pnpm add map-config
yarn add map-config
bun add map-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.5.0 |
| Published | 2016-02-24 |
| First published | 2015-09-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Brian Woodward |
| Maintainers | doowb, jonschlinkert |
| Keywords | config, configuration, settings |

## Links

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

## Dependencies (2)

- [async](https://npm.io/package/async.md) ^1.5.2
- [array-unique](https://npm.io/package/array-unique.md) ^0.2.1

## 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

- 0.5.0 (latest) — 2016-02-24
- 0.4.4 — 2016-02-15
- 0.4.3 — 2016-02-14
- 0.4.2 — 2016-02-02
- 0.4.1 — 2016-01-29
- 0.4.0 — 2016-01-17
- 0.3.0 — 2015-11-10
- 0.2.2 — 2015-11-06
- 0.2.1 — 2015-10-22
- 0.2.0 — 2015-10-20
- 0.1.1 — 2015-10-08
- 0.1.0 — 2015-09-21

## README

# map-config [![NPM version](https://img.shields.io/npm/v/map-config.svg)](https://www.npmjs.com/package/map-config) [![Build Status](https://img.shields.io/travis/doowb/map-config.svg)](https://travis-ci.org/doowb/map-config)

> Map configuration objects to application methods.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm i map-config --save
```

## Usage

```js
var MapConfig = require('map-config');
```

## API

### [MapConfig](index.js#L24)
Create a new instance of MapConfig with a specified map and application.

**Params**

* `app` **{Object}**: Object containing the methods that will be called based on the map specification.    
* `map` **{Object}**: Optional object specifying how to map a configuration to an application.    

**Example**

```js
var mapper = new MapConfig(app, map);
```

### [.map](index.js#L63)
Map properties to methods and/or functions.

**Params**

* `key` **{String}**: property key to map.    
* `val` **{Function|Object}**: Optional function to call when a config has the given key. Functions will be passed `(val, key, config)` when called. Functions may also take a callback to indicate async usage. May also pass another instance of MapConfig to be processed.    
* `returns` **{Object}** `this`: to enable chaining  

**Example**

```js
mapper
  .map('baz')
  .map('bang', function(val, key, config) {
  });
```

### [.alias](index.js#L122)
Create an `alias` for property `key`.

**Params**

* `alias` **{String}**: Alias to use for `key`.    
* `key` **{String}**: Actual property or method on `app`.    
* `returns` **{Object}**: Returns the instance for chaining.  

**Example**

```js
mapper.alias('foo', 'bar');
```

### [.process](index.js#L143)
Process a configuration object with the already configured `map` and `app`.

**Params**

* `config` **{Object}**: Configuration object to map to application methods.    
* `cb` **{Function}**: Optional callback function that will be called when finished or if an error occurs during processing.    

**Example**

```js
mapper.process(config);
```

### [.addKey](index.js#L217)
Add a key to the `.keys` array. May also be used to add an array of namespaced keys to the `.keys` array. Useful for mapping "sub-configs" to a key in a parent config.

**Params**

* `key` **{String}**: key to push onto `.keys`    
* `arr` **{Array}**: Array of sub keys to push onto `.keys`    
* `returns` **{Object}** `this`: for chaining  

**Example**

```js
mapper.addKey('foo');
console.log(mapper.keys);
//=> ['foo']

var one = new MapConfig();
var two = new MapConfig();
two.map('foo');
two.map('bar');
two.map('baz');

// map config `two` to config `one`
one.map('two', function(val, key, config, next) {
  two.process(val, next);
});

// map keys from config `two` to config `one`
one.addKey('two', two.keys);
console.log(one.keys);
//=> ['two.foo', 'two.bar', 'two.baz']
```

## Related projects
* [assemble](https://www.npmjs.com/package/assemble): Assemble is a powerful, extendable and easy to use static site generator for node.js. Used… [more](https://www.npmjs.com/package/assemble) | [homepage](https://github.com/assemble/assemble)
* [generate](https://www.npmjs.com/package/generate): Fast, composable, highly extendable project generator with a user-friendly and expressive API. | [homepage](https://github.com/generate/generate)
* [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine.… [more](https://www.npmjs.com/package/templates) | [homepage](https://github.com/jonschlinkert/templates)
* [update](https://www.npmjs.com/package/update): Easily keep anything in your project up-to-date by installing the updaters you want to use… [more](https://www.npmjs.com/package/update) | [homepage](https://github.com/update/update)
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://www.npmjs.com/package/verb) | [homepage](https://github.com/verbose/verb)

## Running tests
Install dev dependencies:

```sh
$ npm i -d && npm test
```

## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/doowb/map-config/issues/new).

## Author
**Brian Woodward**

+ [github/doowb](https://github.com/doowb)
+ [twitter/doowb](http://twitter.com/doowb)

## License
Copyright © 2016 [Brian Woodward](https://github.com/doowb)
Released under the [MIT license](https://github.com/doowb/map-config/blob/master/LICENSE).

***

_This file was generated by [verb](https://github.com/verbose/verb), v0.1.0, on February 23, 2016._

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