Description of the path. isAbsolute method in node. js, node. jspath
Method description:
Checks whether the path is an absolute path. An absolute path will be resolved to the same location, whether in the working directory or not.
Syntax:
Copy codeThe Code is as follows:
Path. isAbsolute (path)
Because this method belongs to the path module, You need to introduce the path module (var path = require ("path") before use "))
Receiving parameters:
Path
Example:
Copy codeThe Code is as follows:
// Posix examples:
Path. isAbsolute ('/foo/bar') // true
Path. isAbsolute ('/baz/..') // true
Path. isAbsolute ('qux/') // false
Path. isAbsolute ('.') // false
// Windows examples:
Path. isAbsolute ('// Server') // true
Path. isAbsolute ('C:/foo/.. ') // true
Path. isAbsolute ('bar \ Baz') // false
Path. isAbsolute ('.') // false
Source code:
Copy codeThe Code is as follows:
// Windows version
Exports. isAbsolute = function (path ){
Var result = splitDeviceRe.exe c (path ),
Device = result [1] | '',
IsUnc = device & device. charAt (1 )! = ':';
// UNC paths are always absolute
Return !! Result [2] | isUnc;
};