Private/Test-ReturnFormat.ps1

function Test-ReturnFormat {
    <#
    .SYNOPSIS
        Removes the wrapper from a response and returns the resources in it.

    .DESCRIPTION
        Ghost wraps the resources of a response in a property named after the resource, next to a meta property:
        {"posts":[{...}],"meta":{...}}. This returns the resources one by one. A response without that property
        is returned as it is.

    .EXAMPLE
        Test-ReturnFormat -Result $result -Location $resources.Result

        Returns the posts of every response in $result.
    #>

    [CmdletBinding()]
    [OutputType([object])]
    param(
        # The responses returned by Submit-Request.
        [AllowNull()]
        [AllowEmptyCollection()]
        [object[]] $Result,

        # Name of the property that holds the resources, such as posts.
        [string] $Location
    )

    foreach ($response in $Result) {
        if ($null -eq $response) {
            continue
        }

        if ($Location -and $response.PSObject.Properties[$Location]) {
            $response.$Location
        }
        else {
            $response
        }
    }
}