summaryrefslogtreecommitdiffstats
path: root/lib/api/encodeConfig.js
blob: d83f81abbabd8a0ca60f6b12f8366791a7bc920f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var objectPath = require('object-path');
var deprecate = require('./deprecate');

/**
    Encode a config object into a JS config api

    @param {Output} output
    @param {Config} config
    @return {Object}
*/
function encodeConfig(output, config) {
    var result = {
        values: config.getValues().toJS(),

        get: function(key, defaultValue) {
            return objectPath.get(result.values, key, defaultValue);
        },

        set: function(key, value) {
            return objectPath.set(result.values, key, value);
        }
    };

    deprecate.field(output, 'config.options', result, 'options',
        result.values, '"config.options" property is deprecated, use "config.get(key)" instead');

    return result;
}

module.exports = encodeConfig;