Function pathSegments

  • Retrieves the segments of the pathname from a given URL as an array of strings.

    Example

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

    Example

    Handle an invalid input:

    pathSegments("blog/posts/welcome/").error.message
    // => { ok: false, error: Error('[urls.pathSegments] Expected a valid URL') }

    pathSegments(null)
    // => { ok: false, error: Error('[urls.pathSegments] Expected a valid URL') }

    Parameters

    • url: string

      The URL for which the pathname segments need to be retrieved.

    Returns Result<string[], Error>

    A Result object with either an array of strings representing the path segments if the given URL is valid, or an Error object if the given URL is not valid.

Generated using TypeDoc v0.24.7