RGJS6 Path module.
Methods
-
<static> clean(path [, leadslash])
-
Clean up path. Removes double (//) and trailing slashes.
Note: ignores[protocol]://
double slash!Parameters:
Name Type Argument Description path
string A path.
leadslash
boolean <optional>
Removes leading slash, too.
Returns:
A clean path.
- Type
- string
Examples
// Returns '/path/to/some/folder' rgjs.path.clean('//path/to/some//folder/');
// Returns 'https://www.example.com/path/to/index.html' rgjs.uri.concat('https://', 'www.example.com', 'path', 'to', 'index.html');
-
<static> cleanPath()
-
Clean up path.
Alias of clean().- Deprecated:
-
- Yes
- See:
-
- rgjs/path/clean
-
<static> concat(path1, path2, args)
-
Concat a path.
Parameters:
Name Type Argument Description path1
string A path.
path2
string Another path.
args
* <repeatable>
More paths.
Returns:
The concatonated filepath
- Type
- string
Examples
// Returns '/path/to/some/folder' rgjs.path.concat('/path/to/', '/some', 'folder');
// Optional boolean can be passed as last argument. If true, `concatPath()` applies // `getPath()` on last string argument, stripping the filename. // Returns '/path/to/some/folder' rgjs.path.concat('/path/to/', '/some', 'folder/file.txt', true);
-
<static> concatPath()
-
Concat a path.
Alias of concat().- Deprecated:
-
- Yes
- See:
-
- rgjs/path/concat
-
<static> getBasename(filepath)
-
Get basename from filepath.
Parameters:
Name Type Description filepath
string A path to a file.
Returns:
The filename with extension.
- Type
- string
Example
rgjs.path.getBasename('/path/to/file.txt') // 'file.txt'
-
<static> getExtension(filepath)
-
Get file extension from filepath (or basename).
Parameters:
Name Type Description filepath
string A path to a file or a filename.
Returns:
The extension of the file
- Type
- string
Example
rgjs.path.getExtension('/path/to/file.txt') // 'txt'
-
<static> getName(filepath)
-
Get a filename without extension.
Parameters:
Name Type Description filepath
string A path to a file.
Returns:
The filename with extension.
- Type
- string
Example
rgjs.path.getName('/path/to/file.txt') // 'file' rgjs.path.getName('/path/to/.hidden') // '.hidden'
-
<static> getPath(filepath)
-
Get path from filepath.
Note: this method is quite dumb. It simply strips everything after the last/
.
Make sure the path contains a filename or a single trailing slash!
See 2nd example for situations that may yield unexpected results.Parameters:
Name Type Description filepath
string A path to a file.
Returns:
The path to the file, excluding the filename.
- Type
- string
Examples
rgjs.path.getPath('/path/to/file.txt'); // '/path/to'
// getPath() is dumb. Make sure the path contains a filename or a single trailing slash! rgjs.path.getPath('/path/to/folder'); // '/path/to' // Oops! 'folder' is stripped! rgjs.path.getPath('/path/to/folder//'); // '/path/to/folder/' // Oops! We have a trailing slash! rgjs.path.getPath('/path/to/folder/'); // '/path/to/folder' // Single trailing slash, works as expected.