• Extracts the directory name from a given file path.

    Example

    dirname('/home/demo/pictures/dummy.jpeg').value
    // => "/home/demo/pictures"

    dirname('/home/demo/pictures').value
    // => "/home/demo/"

    dirname('C:/Users/Documents/File1.txt').value
    // => 'C:/Users/Documents'

    dirname('/var/www/html/index.html').value
    // => '/var/www/html'

    dirname('C:/Users/Documents/Folder1').value
    // => 'C:/Users/Documents'

    const dname = dirname(12345)
    dname.isOk()
    // => false
    dnane.isErr()
    // true
    dname.error.message
    // Outputs an error => '[paths.dirname] The given path must be a string'

    Parameters

    • path: string

      The file path from which to extract the directory name.

    Returns Result<string, Error>

    A Result object containing the directory name as a string on success, or an Error object if the provided input is not a string.

Generated using TypeDoc v0.24.7