UNPKG

read-config-ng

Version:
40 lines 1.35 kB
import { resolveValue } from './resolve-expression.js'; /** * Replace variables in configuration with resolved values */ export function replaceVariables(marker, config, values, opts = {}) { return resolve('', config, marker, values, opts); } /** * Recursively resolve variables in configuration */ function resolve(prop, config, marker, values, opts) { if (typeof config === 'string') { // Resolve string expressions return resolveValue(prop, config, marker, values, opts); } else if (Array.isArray(config)) { // Resolve array elements const result = []; const propPrefix = prop.length ? prop + '.' : ''; config.forEach((item, idx) => { result.push(resolve(propPrefix + idx, item, marker, values, opts)); }); return result; } else if (typeof config === 'object' && config !== null) { // Resolve object properties const result = {}; const propPrefix = prop.length ? prop + '.' : ''; Object.keys(config).forEach(key => { result[key] = resolve(propPrefix + key, config[key], marker, values, opts); }); return result; } else { // Return primitive values as-is return config; } } export default replaceVariables; //# sourceMappingURL=replace-variables.js.map