From c9648bb03dec80f5a6d08f93af13bf635b84050d Mon Sep 17 00:00:00 2001 From: Markus Felten Date: Thu, 27 Jul 2017 22:55:44 +0200 Subject: [PATCH] feat: expand as async function BREAKING CHANGE: node 6.x no longer supportd --- src/expander.js | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/expander.js b/src/expander.js index 918d4e1d..56b81170 100644 --- a/src/expander.js +++ b/src/expander.js @@ -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 };