Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 16:28:17
Original
1729 people have browsed it

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;
};
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template