This article describes how to use the path. isAbsolute method in node. js. This article describes the method description, syntax, examples, and source code implementation of path. isAbsolute. For more information, see
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:
The 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:
The 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:
The 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;
};