Function makeImagePath

  • Generates an image path URL by concatenating the base URL, artifact, pathname, and filename.

    Example

     makeImagePath('', 'pages', 'about', 'cover.png')
    // => { ok: true, value: '/pages/about/cover.png' }

    makeImagePath('', 'resources', 'posts/welcome', 'cover.png')
    // => { ok: true, value: '/resources/posts/welcome/cover.png' }

    makeImagePath('https://www.example.com', '', 'about', 'cover.png')
    // => { ok: true, value: '/about/cover.png' }

    Example

    Handle an invalid input string:

    makeImagePath(null)
    // => { ok: false, error: Error('[urls.makeImagePath] Expected string values for all parameters') }

    Parameters

    • baseURL: string

      The base URL to be used for generating the image path URL.

    • artifact: "" | "pages" | "resources" = ''

      The artifact type to be used for generating the image path URL. It can be 'pages' | 'resources' | ''. Defaults to an empty string ('').

    • pathname: string

      The pathname to be appended to the base URL and artifact.

    • filename: string

      The filename to be appended to the base URL, artifact, and pathname.

    Returns Result<string, Error>

    A Result object with either a string representing the image path URL if all inputs are valid strings, or an Error object if any of the inputs are not valid strings.

Generated using TypeDoc v0.24.7