bittib010 / YamlCommunityRulesConverter

0 stars 0 forks source link

tfazurerm template - PascalCasings for tactics... #8

Open bittib010 opened 2 months ago

bittib010 commented 2 months ago

Something like:

function ConvertTo-PascalCase { param ( [string]$inputString )

# Convert the string to lowercase and split it into words
$words = $inputString.ToLower() -split '\s+'

# Capitalize the first letter of each word
for ($i = 0; $i -lt $words.Length; $i++) {
    if ($words[$i].Length -gt 0) {
        $firstChar = $words[$i].Substring(0,1).ToUpper()
        $remainingChars = $words[$i].Substring(1)
        $words[$i] = $firstChar + $remainingChars
    }
}

# Join the words together without spaces
$pascalCaseString = -join $words

return $pascalCaseString

}

And then do: $tacticsTags = $null if ($row.Tactics) {

Split tactics into individual tactics based on comma

$tacticList = $row.Tactics -split ','
$processedTactics = @()

foreach ($tactic in $tacticList) {
    $tactic = $tactic.Trim()
    # Check if the tactic is already in PascalCase
    if ($tactic -match '^[A-Z][a-z]+(?:[A-Z][a-z]+)*$') {
        # Already PascalCase, keep as is
        $processedTactics += $tactic
    } else {
        # Convert to PascalCase
        $convertedTactic = ConvertTo-PascalCase -inputString $tactic
        $processedTactics += $convertedTactic
    }
}

# Join the processed tactics back into a comma-separated string
$finalTacticsString = $processedTactics -join ','

# Assign to tacticsTags
$tacticsTags = "    `"tactics`" = `"$finalTacticsString`","

}

bittib010 commented 2 months ago

example for hunting