Gathering detailed insights and metrics for @antora/expand-path-helper
Gathering detailed insights and metrics for @antora/expand-path-helper
Gathering detailed insights and metrics for @antora/expand-path-helper
Gathering detailed insights and metrics for @antora/expand-path-helper
npm install @antora/expand-path-helper
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
No dependencies detected.
A Node.js module that provides a helper function to expand a path to a normalized absolute path.
This function also expands the following shorthand expressions when used as the first path segment: dot (.
), tilde (~
), or tilde plus (~+
).
The expanded path is system dependent.
Developed for use in Antora.
1$ npm i @antora/expand-path-helper
1function expandPath (path[, context])
Expands the specified path to a normalized absolute path. The main purpose of this function is path expansion and normalization.
path
<string> - The path to expand.
This parameter is required.
If the path is already absolute, the path is normalized and returned.context
<Object> - Named parameters that control how the path is resolved.
All named parameters are optional.
This parameter can also be specified as a String, in which case it’s used as the base context argument.
Default: {}
.
base
<string> - The base directory from which to resolve a relative path instead of the working directory.
Default: ~+
cwd
<string> - The absolute directory to use as the working directory instead of the current working directory.
If not specified, the current working directory is used.
Default: undefined
dot
<string> - The value to use to replace a leading dot (.
) segment.
If the value is .
, the value of the base
context argument is used instead.
Default: .
If the first segment of the path argument, the base context argument, or the dot context argument is ~
or ~+
, that value is expanded to the user’s home directory or current working directory, respectively.
If the first segment of the path argument is .
, that value is replaced with the dot context argument after the dot context argument is expanded.
The output of expandPath
depends on the system on which it is run (specifically on the path.sep
value).
1const expandPath = require('@antora/expand-path-helper') 2 3expandPath('/absolute/path') 4//=> /absolute/path 5 6expandPath('/absolute/./path/..') 7//=> /absolute 8 9expandPath('foo/bar') 10//=> $PWD/foo/bar 11 12expandPath('./foo/bar') 13//=> $PWD/foo/bar 14 15expandPath('~/foo/bar') 16//=> $HOME/foo/bar 17 18expandPath('~+/foo/bar') 19//=> $PWD/foo/bar 20 21expandPath('~+/foo/bar', { cwd: '/working/dir' }) 22//=> /working/dir/foo/bar 23 24expandPath('foo/bar', '/base/dir') 25//=> /base/dir/foo/bar 26 27expandPath('foo/bar', { base: '/base/dir' }) 28//=> /base/dir/foo/bar 29 30expandPath('./foo/bar', { base: '/base/dir' }) 31//=> /base/dir/foo/bar 32 33expandPath('./foo/bar', { dot: '/dot/dir' }) 34//=> /dot/dir/foo/bar
1const expandPath = require('@antora/expand-path-helper') 2 3expandPath('C:\\absolute\\path') 4//=> C:\absolute\path 5 6expandPath('C:/absolute/path') 7//=> C:\absolute\path 8 9expandPath('C:\\absolute\\.\\path\\..') 10//=> C:\absolute 11 12expandPath('foo\\bar') 13//=> C:\current\directory\foo\bar 14 15expandPath('.\\foo\\bar') 16//=> C:\current\directory\foo\bar 17 18expandPath('~\\foo\\bar') 19//=> C:\Users\user\foo\bar 20 21expandPath('~+\\foo\\bar') 22//=> C:\current\directory\foo\bar 23 24expandPath('~+\\foo\\bar', { cwd: 'C:\\working\\dir' }) 25//=> C:\working\dir\foo\bar 26 27expandPath('foo\\bar', 'C:\\base\\dir') 28//=> C:\base\dir\foo\bar 29 30expandPath('foo\\bar', { base: 'C:\\base\\dir' }) 31//=> C:\base\dir\foo\bar 32 33expandPath('.\\foo\\bar', { base: 'C:\\base\\dir' }) 34//=> C:\base\dir\foo\bar 35 36expandPath('.\\foo\\bar', { dot: 'C:\\dot\\dir' }) 37//=> C:\dot\dir\foo\bar
On Windows, the input path may use forward slashes, but the expanded path will always have backslashes.
Copyright (C) 2018-present by OpenDevise Inc. and the individual contributors to Antora.
Use of this software is granted under the terms of the Mozilla Public License Version 2.0 (MPL-2.0).
No vulnerabilities found.
No security vulnerabilities found.