Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
@antora/expand-path-helper
Advanced tools
A helper function to expand a path to an absolute path, including expanding the first segment if it matches a shorthand expression, dot (.), tilde (~), or tilde plus (~+).
A module for Node.js that provides a helper function to expand a path to an absolute path.
This function expands the first segment if it matches a shorthand expression, dot (.
), tilde (~
), or tilde plus (~+
).
The expanded path is system dependent.
Developed for use in Antora.
$ npm i @antora/expand-path-helper
or
$ yarn add @antora/expand-path-helper
function expandPath (path, start = '~+', dot = '.') { ... }
Converts path to an absolute path.
path
- The path to expand.
This parameter is required and must not be falsy.start
- The starting directory from which to anchor a relative path.
This parameter is optional.
It defaults to the current working directory of the process (~+
).dot
- The value to use to replace a leading dot (.
) segment.
This parameter is optional.
If the value of this parameter is itself .
, which is the default, it uses the value of the start parameter.The main purpose of this function is path expansion.
If the first segment of the path, the value of the start parameter, or the value of the dot parameter matches ~
or ~+
, that value is expanded to the user's home directory or current working directory, respectively.
If the first segment of the path matches .
, that value is replaced with the value of the dot parameter after being expanded.
The output of expandPath
depends on the system on which it is run (specifically on the path.sep
value).
const expandPath = require('@antora/expand-path-helper')
expandPath('/absolute/path')
//=> /absolute/path
expandPath('foo/bar')
//=> /current/directory/foo/bar
expandPath('./foo/bar')
//=> /current/directory/foo/bar
expandPath('~/foo/bar')
//=> /home/user/foo/bar
expandPath('~+/foo/bar')
//=> /current/directory/foo/bar
expandPath('foo/bar', '/start/dir')
//=> /start/dir/foo/bar
expandPath('./foo/bar', '/start/dir')
//=> /start/dir/foo/bar
expandPath('./foo/bar', '~+', '/start/dir')
//=> /start/dir/foo/bar
const expandPath = require('@antora/expand-path-helper')
expandPath('C:\\absolute\\path')
//=> C:\absolute\path
expandPath('foo\\bar')
//=> C:\current\directory\foo\bar
expandPath('.\\foo\\bar')
//=> C:\current\directory\foo\bar
expandPath('~\\foo\\bar')
//=> C:\Users\user\foo\bar
expandPath('~+\\foo\\bar')
//=> C:\current\directory\foo\bar
expandPath('foo\\bar', 'C:\\start\\dir')
//=> C:\start\dir\foo\bar
expandPath('.\\foo\\bar', 'C:\\start\\dir')
//=> C:\start\dir\foo\bar
expandPath('.\\foo\\bar', '~+', 'C:\\start\\dir')
//=> C:\start\dir\foo\bar
On Windows, the input path may contain forward slashes, but the expanded path will always have backslashes.
Copyright (C) 2018 OpenDevise Inc. and the Antora Project.
Use of this software is granted under the terms of the Mozilla Public License Version 2.0 (MPL-2.0).
FAQs
Provides a helper function to expand a path to a normalized absolute path. This function also expands dot, tilde, and tilde plus when used as the first path segment.
The npm package @antora/expand-path-helper receives a total of 22,410 weekly downloads. As such, @antora/expand-path-helper popularity was classified as popular.
We found that @antora/expand-path-helper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.