Skip to content

Commit

Permalink
feat: expand as async function
Browse files Browse the repository at this point in the history
BREAKING CHANGE: node 6.x no longer supportd
  • Loading branch information
arlac77 committed Jul 27, 2017
1 parent 1e85f37 commit c9648bb
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions src/expander.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,29 @@ const os = require('os');
* @returns {Promise}
* @fulfil {object} - expanded configuration
*/
export function expand(config, options = {}) {
try {
const context = {
constants: Object.assign(
{
basedir: process.cwd(),
os
},
options.constants
),
functions: Object.assign({}, functions, options.functions)
};
export async function expand(config, options = {}) {
const context = {
constants: Object.assign(
{
basedir: process.cwd(),
os
},
options.constants
),
functions: Object.assign({}, functions, options.functions)
};

const parser = new ConfigParser();
const parser = new ConfigParser();

const ee = createContext({
evaluate: (expression, _unusedContext, path) => {
context.path = path;
const ast = parser.parse(expression, context);
return ast.value;
}
});
const ee = createContext({
evaluate: (expression, _unusedContext, path) => {
context.path = path;
const ast = parser.parse(expression, context);
return ast.value;
}
});

return Promise.resolve(ee.expand(config));
} catch (err) {
return Promise.reject(err);
}
return ee.expand(config);
}

export { createValue };

0 comments on commit c9648bb

Please sign in to comment.