internal/functions/Format-CmdFavString.ps1

function Format-CmdFavString {
    <#
        .SYNOPSIS
            Formats PowerShell code according to CmdFav formatting rules.
 
        .DESCRIPTION
            This function accepts PowerShell code as a string, normalizes line endings, and formats
            the code according to the Invoke-Formatter settings stored in the CmdFav configuration.
            The formatted code is returned as a string.
 
        .PARAMETER ScriptText
            The PowerShell code to format. Can be provided as an argument or via the pipeline.
 
        .EXAMPLE
            $formatted = Format-CmdFavString -ScriptText $code
 
            Formats the contents of the variable $code using the CmdFav formatting settings.
 
        .EXAMPLE
            Get-Content .\script.ps1 | Format-CmdFavString
 
            Formats the contents of a file via the pipeline.
 
        .NOTES
            The formatting rules are loaded from the PSFramework configuration entry
            'CmdFav.Formatting.Settings'. You can customize these settings using Set-PSFConfig.
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
        [string]$ScriptText
    )
    begin {
        $settings=Get-PSFConfigValue -FullName 'CmdFav.Formatting.Settings'
    }
    process {
        $normalized = ($ScriptText -replace "`r`n|`r|`n", "`n")
        $formatted = $normalized | Invoke-Formatter -settings $settings
        return $formatted
    }
}