Skip to content

talmobi/path-shorten

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published