| gio | a71316d | 2025-05-24 09:41:36 +0400 | [diff] [blame^] | 1 | const regex = /(?<!\\)\${([^{}]+)}|(?<!\\)\$([A-Za-z_][A-Za-z0-9_]*)/g; |
| 2 | |
| 3 | export function expandValue(value: string): string[] { |
| 4 | const vars = new Set<string>(); |
| 5 | const matches = [...value.matchAll(regex)]; |
| 6 | while (matches.length > 0) { |
| 7 | const match = matches.shift(); |
| 8 | if (match == null) { |
| 9 | break; |
| 10 | } |
| 11 | const [_, bracedExpression, unbracedExpression] = match; |
| 12 | const expression = bracedExpression || unbracedExpression; |
| 13 | const opRegex = /(:\+|\+|:-|-)/; |
| 14 | const opMatch = expression.match(opRegex); |
| 15 | const splitter = opMatch ? opMatch[0] : null; |
| 16 | let r: string[]; |
| 17 | if (splitter != null) { |
| 18 | r = expression.split(splitter); |
| 19 | } else { |
| 20 | r = [expression]; |
| 21 | } |
| 22 | const key = r.shift(); |
| 23 | if (key != null) { |
| 24 | vars.add(key); |
| 25 | } |
| 26 | } |
| 27 | return [...vars]; |
| 28 | } |