GitHub 6248★

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
Follow me on and to get more useful contents.