Crate nodejs_path
source · [−]Expand description
Description
The default operation of the path module varies based on the operating system on which crate is compiling. Specifically, when compiling on a Windows operating system, the path module will assume that Windows-style paths are being used.
So using nodejs_path::basename() might yield different results on POSIX and Windows:
On POSIX:
nodejs_path::basename!("C:\\temp\\myfile.html");
// Returns: "C:\\temp\\myfile.html"On Windows:
nodejs_path::basename!("C:\\temp\\myfile.html");
// Returns: "myfile.html"To achieve consistent results when working with Windows file paths on any operating system, use nodejs_path::win32:
On POSIX and Windows:
assert_eq!(&nodejs_path::win32::basename!("C:\\temp\\myfile.html"), "myfile.html")To achieve consistent results when working with POSIX file paths on any operating system, use nodejs_path::posix:
On POSIX and Windows:
assert_eq!(&nodejs_path::posix::basename!("/tmp/myfile.html"), "myfile.html")Porting
Rust doesn’t support variadic function. So, variadic functions of Node.js must be ported to macros.
- path.basename =>
nodejs_path::basename! - path.delimiter =>
nodejs_path::delimiter - path.dirname =>
nodejs_path::dirname - path.extname =>
nodejs_path::extname - path.format =>
nodejs_path::format - path.isAbsolute =>
nodejs_path::is_absolute - path.join =>
nodejs_path::join! - path.normalize =>
nodejs_path::normalize - path.parse =>
nodejs_path::parse - path.relative =>
nodejs_path::relative! - path.resolve =>
nodejs_path::resolve! - path.sep =>
nodejs_path::sep - path.toNamespacedPath =>
nodejs_path::to_namespaced_path
Re-exports
Modules
nodejs_path::posix provides access to POSIX specific implementations of the path methods.
nodejs_path::win32 provides access to Windows-specific implementations of the path methods.
Macros
Returns the last portion of a path, similar to the Unix basename command. Trailing directory separators are ignored.
The method joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.
Resolves a sequence of paths or path segments into an absolute path.
Structs
Constants
Provides the platform-specific path delimiter:
Provides the platform-specific path segment separator:
Functions
Get current working directory. Just like process.cwd()
Returns the directory name of a path, similar to the Unix dirname command. Trailing directory separators are ignored,
Returns the extension of the path, from the last occurrence of the . (period) character to end of string in the last portion of the path. If there is no . in the last portion of the path, or if there are no . characters other than the first character of the basename of path, an empty string is returned.
Returns a path string from an object. This is the opposite of nodejs_path::parse().
The method determines if path is an absolute path. If the given path is a zero-length string, false will be returned. #Example
The path.normalize() method normalizes the given path, resolving ‘..’ and ‘.’ segments.
Example
method returns the relative path from from to to based on the current working directory. If from and to each resolve to the same path (after calling resolve() on each), a zero-length string is returned.