Skip to content
This repository has been archived by the owner on Mar 11, 2018. It is now read-only.
/ pppath Public archive

Join strings to form a valid file path.

License

Notifications You must be signed in to change notification settings

yuanqing/pppath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pppath.js npm Version Build Status Coverage Status

Join strings to form a valid path.

API

pppath(parts [, filename])

Returns a String, the result of joining parts. filename is appended to the returned path if the last element of parts does not end with a file extension.

// without `filename`
pppath(['/foo/', '/bar']);            //=> '/foo/bar'
pppath(['http://', '/foo/', '/bar']); //=> 'http://foo/bar'

// with `filename`
pppath(['/foo/', '/bar'], 'index.html');               //=> '/foo/bar/index.html'
pppath(['/foo/', '/bar/'], 'index.html');              //=> '/foo/bar/index.html'
pppath(['/foo/', '/bar.js'], 'index.html');            //=> '/foo/bar.js'
pppath(['http://', '/foo/', '/bar'], 'index.html');    //=> 'http://foo/bar/index.html'
pppath(['http://', '/foo/', '/bar/'], 'index.html');   //=> 'http://foo/bar/index.html'
pppath(['http://', '/foo/', '/bar.js'], 'index.html'); //=> 'http://foo/bar.js'

Consecutive / will be replaced by a single /, with the exception that the character sequence :// will remain intact. This is not the behaviour of the Node API’s path.join:

// :(
path.join('http://', '/foo/', '/bar'); //=> 'http:/foo/bar'

// :)
pppath(['http://', '/foo/', '/bar']);  //=> 'http://foo/bar'

More usage examples are in the tests.

Installation

Install via npm:

$ npm i --save pppath

Changelog

  • 0.1.0
    • Initial release

License

MIT license