internal/functions/resolve/Resolve-String.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function Resolve-String
{
    [CmdletBinding()]
    Param (
        [string[]] $Text
    )
    
    begin
    {
        [regex] $mappingRegex = "{{ ([\dA-Za-z]*) }}"
    }
    process
    {
        foreach ($item in $Text) {
            foreach ($match in $mappingRegex.Matches($item)) {
                $replaceValue = $script:desiredConfiguration["stringMappings"] | ? {$_.name -eq $match.Groups[1].Value}
                if ($replaceValue) {
                    $item = $item -replace $match.Value, $replaceValue.replace
                }
            }
            $item
        }
    }
}