Skip to main content

ensureAbsolutePath

Callable

  • ensureAbsolutePath(path: string): string

  • Guarantees a path is absolute by prepending / if needed.

    Useful when working with user-provided paths that might be relative, or when you need to normalize edge cases like empty strings.

    For example:

    ensureAbsolutePath('wp-content/uploads') '/wp-content/uploads'

    ensureAbsolutePath('/already/absolute') '/already/absolute'

    ensureAbsolutePath('') '/'


    Parameters

    • path: string

      The path to make absolute.

    Returns string

    An absolute, normalized path starting with /.