UNPKG

@orcdkestrator/orcdk-plugin-localstack

Version:
49 lines 1.78 kB
"use strict"; /** * Utility functions for LocalStack plugin */ Object.defineProperty(exports, "__esModule", { value: true }); exports.expandEnvironmentVariables = expandEnvironmentVariables; exports.expandEnvironmentVariablesInObject = expandEnvironmentVariablesInObject; function expandEnvironmentVariables(value) { if (!value || typeof value !== 'string') { return value; } // Replace ${VAR_NAME} style variables let expanded = value.replace(/\$\{([^}]+)\}/g, (match, varName) => { const envValue = process.env[varName]; return envValue !== undefined ? envValue : match; }); // Replace $VAR_NAME style variables (but not if followed by { to avoid double replacement) expanded = expanded.replace(/\$([A-Za-z_][A-Za-z0-9_]*)(?!\{)/g, (match, varName) => { const envValue = process.env[varName]; return envValue !== undefined ? envValue : match; }); return expanded; } /** * Recursively expands environment variables in an object * * @param obj The object potentially containing environment variables in string values * @returns The object with environment variables expanded in all string values */ function expandEnvironmentVariablesInObject(obj) { if (obj === null || obj === undefined) { return obj; } if (typeof obj === 'string') { return expandEnvironmentVariables(obj); } if (Array.isArray(obj)) { return obj.map(item => expandEnvironmentVariablesInObject(item)); } if (typeof obj === 'object') { const result = {}; for (const [key, value] of Object.entries(obj)) { result[key] = expandEnvironmentVariablesInObject(value); } return result; } return obj; } //# sourceMappingURL=utils.js.map