Skip to main content

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

Comments