• Extracts the filename from a given file path.

    Example

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

    filename('/home/demo/profile').value
    // => "profile"

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

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

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

    filename('https://example.com/assets/image.png').value
    // => 'image.png'

    const fname = filename(12345)
    fname.isOk()
    // => false
    fname.isErr()
    // true
    fname.error.message
    // => '[paths.filename] Expected string value as input'

    Parameters

    • path: string

      The file path from which to extract the filename.

    Returns Result<string, Error>

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

Generated using TypeDoc v0.24.7