Functions/Private/Split-Version.ps1


function split-version {
    [CmdletBinding()]
    [OutputType([hashtable])]
    param ($version)
    $versionregex = '^(?<version>\d+\.\d+\.\d+(\.+\d+)?)(\-(?<prerelease>.+))?$'
    
    if ($version -match $versionregex) {
        
        write-Verbose "splitting out $version "
        write-Verbose ($matches | Format-List | out-string)

        return @{
            version    = $Matches.version
            prerelease = $matches.prerelease
        }
    }
    else {
        Throw "Not a valid version $version should match this pattern $versionregex"
    }
}