Types/OpenPackage/get_Eponym.ps1

<#
.SYNOPSIS
    Gets all Eponyms in a Package
.DESCRIPTION
    Gets all Eponyms within an OpenPackage.

    Eponyms are files whose name matches their directory.

    For example:

    `/foo/foo.ps1` is an eponym
    `/foo/foo.md` is an eponym
    `/foo/bar.ps1` is not an eponym

    If a package has an an identifier,
    any files whose name matches this identifier will be considered an eponym.
.NOTES
    Multiple eponyms may exist for a given path.

    Anything before the first period `.` will be considered the name of the file.
#>

param()

if (-not $this.GetParts) { return }
foreach ($part in $this.GetParts()) {
    $partSegments = @($part.Uri -split '/+' -ne '')
    if ($partSegments.Count -eq 1) {
        if ($partSegments[0] -replace '\..+$' -eq $this.Identifier) {
            $part
            continue
        }
    }
    if ($partSegments.Count -ge 2) {
        if ($partSegments[-2] -eq 
            ($partSegments[-1] -replace '\..+$')
        ) {
            $part
            continue
        }
    }
}