path.isAbsolute(path)


path.isAbsolute() 方法确定 path 是否为绝对路径。

¥The path.isAbsolute() method determines if path is an absolute path.

如果给定的 path 是零长度字符串,则将返回 false

¥If the given path is a zero-length string, false will be returned.

例如,在 POSIX 上:

¥For example, on POSIX:

path.isAbsolute('/foo/bar'); // true
path.isAbsolute('/baz/..');  // true
path.isAbsolute('qux/');     // false
path.isAbsolute('.');        // false 

在 Windows 上:

¥On Windows:

path.isAbsolute('//server');    // true
path.isAbsolute('\\\\server');  // true
path.isAbsolute('C:/foo/..');   // true
path.isAbsolute('C:\\foo\\..'); // true
path.isAbsolute('bar\\baz');    // false
path.isAbsolute('bar/baz');     // false
path.isAbsolute('.');           // false 

如果 path 不是字符串,则抛出 TypeError

¥A TypeError is thrown if path is not a string.