Function parentPathname

  • Retrieves the parent pathname of a given URL by removing the last segment of the pathname.

    Example

    parentPathname("https://www.example.com/page/subpage")
    // => { ok: true, value: 'page' }

    Example

    Handle an invalid input:

    parentPathname("page/subpage")
    // => { ok: false, error: Error('[urls.parentPathname] Expected a valid URL') }

    Parameters

    • url: string

      The URL for which the parent pathname needs to be retrieved.

    Returns Result<string, Error>

    A Result object with either a string representing the parent pathname if the given URL is valid, or an Error object if the given URL is not valid.

Generated using TypeDoc v0.24.7