https://github.com/doowb/map-config
Map configuration objects to application methods.
https://github.com/doowb/map-config
Last synced: about 1 month ago
JSON representation
Map configuration objects to application methods.
- Host: GitHub
- URL: https://github.com/doowb/map-config
- Owner: doowb
- License: mit
- Created: 2015-09-21T23:38:31.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-24T04:37:55.000Z (about 9 years ago)
- Last Synced: 2024-10-11T03:58:19.030Z (7 months ago)
- Language: JavaScript
- Size: 47.9 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# map-config [](https://www.npmjs.com/package/map-config) [](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._