Returns the last segment of a given path string.
lastSegment('/home/user/documents/file.txt').value// => file.txtlastSegment('/home/user/documents/').value// => ''lastSegment('/home/user/documents').value// => 'documents'lastSegment('file.txt').value// => 'file.txt'lastSegment('').value// => ''const seg1 = lastSegment(null)seg1.isOk()// => falseseg1.isErr()// => trueseg1.error.message// => [paths.lastSegment] Expected string value as inputconst seg2 = lastSegment(12345)seg2.isOk()// => falseseg2.isErr()// => trueseg2.error.message// => Error: [paths.lastSegment] Expected string value as input Copy
lastSegment('/home/user/documents/file.txt').value// => file.txtlastSegment('/home/user/documents/').value// => ''lastSegment('/home/user/documents').value// => 'documents'lastSegment('file.txt').value// => 'file.txt'lastSegment('').value// => ''const seg1 = lastSegment(null)seg1.isOk()// => falseseg1.isErr()// => trueseg1.error.message// => [paths.lastSegment] Expected string value as inputconst seg2 = lastSegment(12345)seg2.isOk()// => falseseg2.isErr()// => trueseg2.error.message// => Error: [paths.lastSegment] Expected string value as input
The path string.
A Result with the last segment as a string on success, and an Error object if the provided input is not a string.
Result
Error
Generated using TypeDoc v0.24.7
Returns the last segment of a given path string.
Example