TidyPath
Extend native nodeJS path module
How to use
Prerequisite
Node JS
Example
lvls()
Returns an array of arrays. Each array represents a lvl (depth) of path (number of path separators). Shallow to deepest level.
var path = ; var paths = 'hello' 'foo/bar' 'hello/world' 'hello/world/tidy/' path;/*[ ['hello'], ['foo/bar','hello/world'], ['hello/world/tidy/'],];*/
byDepth()
Returns paths by depth (number of path separators). Shallow to deepest.
var path = ; var paths = 'hello' 'hello/world/foo/bar' 'hello/world/tidy/' //ignores trailing separator 'hello/world' 'foo/bar' path;/*['hello','foo/bar','hello/world','hello/world/tidy/', //won't remove trailing separator'hello/world/foo/bar']);*/
ext()
Returns file extension.
var path = ; path //'.txt'path //'.txt'path //''path //''
rmExt()
//Removes file extension from path.
var path = ; path //'foo'path //'foo/bar.ver7'path //'foo/bar'path //'.txt'
file()
Returns file name (including file extension).
var path = ; path //'foo.txt'path //'foo.txt'path //'foo.ver100.txt'path //'bar.txt'path //'hello.txt'path //''path //''path //'.dotfile'path //''path //''
filename()
Synonym for file()
dotfile()
Returns dotfile in path.
var path = ; path //''path //''path //''path //''path //''path //'.bar'path //'.txt'
tree()
Returns directory of path.
var path = ; path //'./hello'path //'hello/world'path //'hello/world'path //'hello/world/'path //'hello/world'path //'.'path //''path //''path //''
filter()
Returns a subset based on filter. Filter can be file extension as string or array of strings, or filter can be a function.
var path = ;var paths = 'hello.js' 'hello/world.txt' '.dot' 0 ; path; //['./hello.txt']path; //['hello.js']path; //['hello.js']path; //['.dot']path; //['hello.js','hello/world.txt','.dot']path; //['hello.js','hello/world.txt','.dot',0];
isFile()
Returns true/false path is a file (either has a file extension or is a dotfile).
path //truepath //truepath //falsepath //truepath //truepath //truepath //truepath //falsepath //falsepath //false
separator
pathseparator //on Windows \ and / on POSIX