path-shorten

0.1.2 • Public • Published

npm npm mac ubuntu windows

path-shorten

Simple path shortener

Easy to use

const pathShorten = require( 'path-shorten' )
console.log( pathShorten( '/one/two/three/four/five.txt' ) )
console.log( pathShorten( 'C:\\Users\\mollie\\Documents\\\\some-project' ) )
console.log( pathShorten( '/Users/mollie/foo/bar' ) )
/one/two/thr/fou/five.txt
c/Use/mol/Doc/some-project
~/foo/bar

Why

To transform paths to the gist and reduce clutter.

How

Simple string manipulation.

Usage

const pathShorten = require( 'path-shorten' )
 
// default options
const opts = {
  home: true, // attempt to transform homedir to '~'
  homedir: require( 'os' ).homedir(),
  length: 3, // path truncation max length
}
 
// optional post transformation function ( for each url found in text )
opts.post = function ( url ) {
  return '' + url + ' ]'
}
 
const text = 'text with /path/like/stuff.txt'
console.log( pathShorten( text, opts ) )
text with [ /pat/lik/stuff.txt ]

Similar to vim's pathshorten ( but not identical )

pathshorten({expr})                      pathshorten()
  Shorten directory names in the path {expr} and return the
  result.  The tail, the file name, is kept as-is.  The other
  components in the path are reduced to ${ opts.length || 3 } letters.  Leading
  '~' and '.' characters are kept.
  
  Example:
  :echo pathshorten('~/.vim/autoload/myfile.vim')
  ~/.v/a/myfile.vim
                        
  It doesn't matter if the path exists or not.

Test

npm test

Readme

Keywords

none

Package Sidebar

Install

npm i path-shorten

Weekly Downloads

8

Version

0.1.2

License

MIT

Unpacked Size

5.82 kB

Total Files

3

Last publish

Collaborators

  • talmobi