Home  >  Article  >  Web Front-end  >  Instructions for using path.isAbsolute method in node.js_node.js

Instructions for using path.isAbsolute method in node.js_node.js

WBOY
WBOYOriginal
2016-05-16 16:28:171676browse

Method description:

Check whether path is an absolute path. An absolute path will resolve to the same location whether in the working directory or not.

Grammar:

Copy code The code is as follows:

path.isAbsolute(path)

Since this method belongs to the path module, the path module needs to be introduced before use (var path= require(“path”) )

Receive parameters:

path path path

Example:

Copy code 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:

Copy code The code is as follows:

// windows version
exports.isAbsolute = function(path) {
var result = splitDeviceRe.exec(path),
device = result[1] || '',
isUnc = device && device.charAt(1) !== ':';
// UNC paths are always absolute
Return !!result[2] || isUnc;
};
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn