• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// replace any ${ENV} values with the appropriate environ.
2
3const envExpr = /(?<!\\)(\\*)\$\{([^${}]+)\}/g
4
5module.exports = (f, env) => f.replace(envExpr, (orig, esc, name) => {
6  const val = env[name] !== undefined ? env[name] : `$\{${name}}`
7
8  // consume the escape chars that are relevant.
9  if (esc.length % 2) {
10    return orig.slice((esc.length + 1) / 2)
11  }
12
13  return (esc.slice(esc.length / 2)) + val
14})
15