Socket
Socket
Sign inDemoInstall

@antora/expand-path-helper

Package Overview
Dependencies
0
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @antora/expand-path-helper

A helper function to expand a path to an absolute path, first resolving leading shorthands such as dot (.), tilde (~), and tilde plus (~+).


Version published
Weekly downloads
23K
decreased by-3.7%
Maintainers
2
Created
Weekly downloads
 

Readme

Source

@antora/expand-path-helper

A node module that exports a helper function to expand a path to an absolute path, first resolving leading shortcuts such as dot (.), tilde (~), and tilde plus (~+). Developed for use in Antora.

Install

$ npm i @antora/expand-path-helper

or

$ yarn add @antora/expand-path-helper

Usage

function expandPath (path, start = process.cwd(), defaultPrefix = '~+') { ... }
  • The first parameter (path) is the path to expand. This parameter is required and must not be falsy.
  • The second parameter (start) is the starting directory to use to expand a leading '.' segment. This parameter is optional. It defaults to the current working directory of the process.
  • The third parameter (defaultPrefix) is the prefix (first segment) to prepend to the path if the path is not anchored (e.g., dir/file). This parameter is optional.

By default, a path which is not anchored is resolved starting from the current working directory of the process. This behavior can be changed by passing a different defaultPrefix value, such as . (uses the value of start), ~ (uses the user's home directory). The default is the equivalent of passing ~+.

*nix

const expandPath = require('@antora/expand-path-helper')

expandPath('/absolute/path')
//=> /absolute/path

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

Windows

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:\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', '/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).

Keywords

FAQs

Last updated on 22 Feb 2018

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc