What is path-is-absolute?
The path-is-absolute npm package provides a simple utility to check if a given path is an absolute path. In different operating systems, an absolute path is defined differently, and this package takes those differences into account, offering a consistent API across environments.
What are path-is-absolute's main functionalities?
Check if a path is absolute
This feature allows you to check if a given path string represents an absolute path on the current operating system. The function returns a boolean value: true if the path is absolute, and false otherwise.
var pathIsAbsolute = require('path-is-absolute');
console.log(pathIsAbsolute('/home/foo')); // On Unix: true
console.log(pathIsAbsolute('C:\\path\\to\\file')); // On Windows: true
console.log(pathIsAbsolute('foo/bar')); // false
Other packages similar to path-is-absolute
is-absolute
Similar to path-is-absolute, is-absolute checks if a given path is absolute. It provides a more comprehensive API with additional checks and utilities around path analysis compared to path-is-absolute.
is-relative
While is-relative serves the opposite purpose of path-is-absolute, it is relevant in the context of path analysis. It checks if a path is relative, which can be useful in conjunction with path-is-absolute for applications that need to validate paths extensively.
path-is-absolute
Node.js 0.12 path.isAbsolute()
ponyfill
Ponyfill: A polyfill that doesn't overwrite the native method
Install
$ npm install --save path-is-absolute
Usage
var pathIsAbsolute = require('path-is-absolute');
pathIsAbsolute('/home/foo');
pathIsAbsolute('C:/Users/');
pathIsAbsolute.posix('/home/foo');
API
See the path.isAbsolute()
docs.
pathIsAbsolute(path)
pathIsAbsolute.posix(path)
The Posix specific version.
pathIsAbsolute.win32(path)
The Windows specific version.
License
MIT © Sindre Sorhus