Module path
File path processing module
Reference method:
1var path = require('path');
Static function
normalize
Standardize the path, process information such as the parent directory in the path
1static String path.normalize(String path);
Call parameters:
- path: String, the given unprocessed path
Return result:
- String, Return the processed path
basename
Query the file name in the path, if the extension is specified, the matching extension will be automatically canceled
1
2static String path.basename(String path,
String ext = "");
Call parameters:
- path: String, the path of the given query
- ext: String, specify the extension, if there is a qualified extension in the file name, it will be automatically canceled
Return result:
- String, Return file name
extname
Query the file extension in the path
1static String path.extname(String path);
Call parameters:
- path: String, the path of the given query
Return result:
- String, Return the obtained extension
format
Try to format an object as a path
1static String path.format(Object pathObject);
Call parameters:
- pathObject: Object
Return result:
- String, Return the formatted path
The parameters supported by pathObject are as follows:
1
2
3
4
5
6
7{
"root": "/",
"dir": "/a/b",
"base": "c.ext",
"ext": ".ext",
"name": "c"
}
parse
Resolve path to path object
1static NObject path.parse(String path);
Call parameters:
- path: String, path
Return result:
- NObject, Return pathObject object
dirname
Directory path in the query path
1static String path.dirname(String path);
Call parameters:
- path: String, the path of the given query
Return result:
- String, Return the path of the obtained directory
fullpath
Convert the given path to the full path
1static String path.fullpath(String path);
Call parameters:
- path: String, the path of the given conversion
Return result:
- String, Return the full path of the conversion
isAbsolute
Identify whether the given path is an absolute path
1static Boolean path.isAbsolute(String path);
Call parameters:
- path: String, given the path that needs to be recognized
Return result:
- Boolean, Return true if it is an absolute path
join
Combine a series of paths into a single path
1static String path.join(...ps);
Call parameters:
- ps: ..., one or more related paths
Return result:
- String, Return the new path
resolve
Combine a series of paths into an absolute path
1static String path.resolve(...ps);
Call parameters:
- ps: ..., one or more related paths
Return result:
- String, Return the new path
relative
Find the relative path from _from to to
1
2static String path.relative(String _from,
String to);
Call parameters:
- _from: String, source path
- to: String, target path
Return result:
- String, Return the relative path
toNamespacedPath
Converted to a namespace-prefixed path. Only valid in windows, other systems return directly.
1static Value path.toNamespacedPath(Value path = undefined);
Call parameters:
- path: Value, the given path.
Return result:
- Value, Return the new path
see: https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
Static properties
sep
String, query the path split character of the current operating system, posix returns'/', windows returns'\'
1static readonly String path.sep;
delimiter
String, query the multi-path combination characters of the current operating system, posix returns':', windows returns';'
1static readonly String path.delimiter;
posix
Object, posix implementation, see path_posix
1static readonly Object path.posix;
win32
Object, windows implementation, see path_win32
1static readonly Object path.win32;