nv-facutil-simple-path
- nv-facutil-simple-path
- simple util of path, same as path.parse, more easy to use
install
- npm install nv-facutil-simple-path
usage
const fac_spath = require("nv-facutil-simple-path");
Dir: end-with "/"
example
const {Dir,Path} = require("nv-facutil-simple-path");
new
var p = new Path("/a/b/c.ext")
> p
/a/b/c.ext
>
getter
> p.sp_
'/'
> p.extsp_
'.'
> p.dir_
/a/b/
> p.fname_
'c.ext'
> p.name_
'c'
> p.ext_
'ext'
>
IS
> p.is_dir()
false
> p.is_file()
true
>
> p.is_abs()
true
> p.is_rel()
false
>
MODIFY
name and .ext
> p.name_ = 'cccc'
'cccc'
> p
/a/b/cccc.ext
> p.ext_ = "jpg"
'jpg'
> p
/a/b/cccc.jpg
> p.dump()
'/a/b/cccc.jpg'
>
dir
prepend append
> p.dir_.append("append")
> p
/a/b/append/cccc.jpg
> p.dir_.prepend("prepend")
> p
/prepend/a/b/append/cccc.jpg
>
replace
> p.dir_.rplc(2,'bbbbb')
undefined
> p
/prepend/a/bbbbb/append/cccc.jpg
>
relativize absolutize
> p.dir_.relize()
> p
prepend/a/bbbbb/append/cccc.jpg
> p.is_rel()
true
> p.is_abs()
false
>
remove
> p
prepend/a/bbbbb/append/cccc.jpg
> p.dir_.rm(1)
'a'
> p
prepend/bbbbb/append/cccc.jpg
>
insert-before and insert-after
// insert before
> p.dir_.ibfr(1,'AAA')
undefined
> p
prepend/AAA/bbbbb/append/cccc.jpg
//insert after
> p.dir_.iaft(2,'BBB')
undefined
> p
prepend/AAA/bbbbb/BBB/append/cccc.jpg
>
rel
> var xx = new Path("/a/b/c/")
> var yy = new Path("/a/b/c/d/x.jpg")
> yy.rel(xx)
d/x.jpg
METHODS
Path
p.dir_
p.sp_
p.fname_
p.name_
p.extsp_
p.ext_
p.is_abs p.is_rel
p.is_dir p.is_file
p.dump
p.rel(p1)
Dir
p.dir_.absize p.dir_.append p.dir_.dump
p.dir_.fst_ p.dir_.iaft p.dir_.ibfr p.dir_.is_abs
p.dir_.is_rel p.dir_.lst_ p.dir_.lsti_ p.dir_.pl_
p.dir_.prepend p.dir_.relize p.dir_.rm p.dir_.rplc
p.dir_.sp_ p.dir_.which
API
LICENSE