|
1 | 1 | 'use strict'
|
2 | 2 |
|
3 |
| -// // like String.prototype.search but returns the last index |
4 |
| -// function _searchLast (str, rgx) { |
5 |
| -// const matches = Array.from(str.matchAll(rgx)) |
6 |
| -// return matches.length > 0 ? matches.slice(-1)[0].index : -1 |
7 |
| -// } |
8 |
| -// |
9 |
| -// function _interpolate (value, processEnv, parsed) { |
10 |
| -// // find the last unescaped dollar sign in the value to evaluate |
11 |
| -// const lastUnescapedDollarSignIndex = _searchLast(value, /(?!(?<=\\))\$/g) |
12 |
| -// |
13 |
| -// // return early unless unescaped dollar sign |
14 |
| -// if (lastUnescapedDollarSignIndex === -1) { |
15 |
| -// return value |
16 |
| -// } |
17 |
| -// |
18 |
| -// // This is the right-most group of variables in the string |
19 |
| -// const rightMostGroup = value.slice(lastUnescapedDollarSignIndex) |
20 |
| -// |
21 |
| -// console.log('rightMostGroup', rightMostGroup) |
22 |
| -// |
23 |
| -// /** |
24 |
| -// * This finds the inner most variable/group divided |
25 |
| -// * by variable name and default value (if present) |
26 |
| -// * ( |
27 |
| -// * (?!(?<=\\))\$ // only match dollar signs that are not escaped |
28 |
| -// * {? // optional opening curly brace |
29 |
| -// * ([\w.]+) // match the variable name |
30 |
| -// * (?::-([^}\\]*))? // match an optional default value |
31 |
| -// * }? // optional closing curly brace |
32 |
| -// * ) |
33 |
| -// */ |
34 |
| -// const matchGroup = /((?!(?<=\\))\${?([\w.]+)(?::-([^}\\]*))?}?)/ |
35 |
| -// const match = rightMostGroup.match(matchGroup) |
36 |
| -// |
37 |
| -// if (match != null) { |
38 |
| -// const [, group, key, defaultValue] = match |
39 |
| -// const replacementString = processEnv[key] || defaultValue || parsed[key] || '' |
40 |
| -// const modifiedValue = value.replace(group, replacementString) |
41 |
| -// |
42 |
| -// // return early for scenario like processEnv.PASSWORD = 'pas$word' |
43 |
| -// if (processEnv[key] && modifiedValue === processEnv[key]) { |
44 |
| -// return modifiedValue |
45 |
| -// } |
46 |
| -// |
47 |
| -// return _interpolate(modifiedValue, processEnv, parsed) |
48 |
| -// } |
49 |
| -// |
50 |
| -// return value |
51 |
| -// } |
52 |
| - |
53 | 3 | function _resolveEscapeSequences (value) {
|
54 | 4 | return value.replace(/\\\$/g, '$')
|
55 | 5 | }
|
|
0 commit comments