[Home] >  String >  Check if a path is relative

Check if a path is relative

JavaScript version

const isRelative = (path) => !/^([a-z]+:)?[\\/]/i.test(path);

TypeScript version

const isRelative = (path: string): boolean => !/^([a-z]+:)?[\\/]/i.test(path);

Examples

isRelative('/foo/bar/baz'); // false
isRelative('C:\\foo\\bar\\baz'); // false
isRelative('foo/bar/baz.txt'); // true
isRelative('foo.md'); // true