nv-path-tree
v1.1.0
Published
nv-path-tree ============ - nv-path-tree is very simple util to change paths to a tree
Downloads
5
Readme
nv-path-tree
- nv-path-tree is very simple util to change paths to a tree
install
- npm install nv-path-tree
usage
const {
parse_one,
paths_to_dict,
dict_to_paths,
load_from_paths,
load_from_pls,
load_from_dict,
} = require("nv-path-tree")
example
parse_one
> parse_one.parse('a/b/c')
[ 'a', 'b', 'c' ]
>
> parse_one.parse('a/b/c/')
[ 'a', 'b', 'c', SP { sp: '/' } ]
>
> parse_one.parse('/a/b/c')
[ '', 'a', 'b', 'c' ]
>
> parse_one.parse('/a/b/c/')
[ '', 'a', 'b', 'c', SP { sp: '/' } ]
>
> parse_one.parse('/a/b/c/./d')
[ '', 'a', 'b', 'c', 'd' ]
>
> parse_one.parse('/a/b/c/../d')
[ '', 'a', 'b', 'd' ]
> parse_one.parse('/a/b/c/.../d')
[ '', 'a', 'd' ]
> parse_one.parse('/a/b/c/..../d')
[ '', 'd' ]
> parse_one.parse('/a/b/c/...../d')
[ 'd' ]
> parse_one.parse('/a/b/c/....../d')
[ 'd' ]
>
> parse_one.parse('/../b/c/../d')
[ 'b', 'd' ]
> parse_one.parse('../b/c/../d')
[ 'b', 'd' ]
>
paths_to_dict
var paths = [
"/a/b/c",
"/a/b/d"
]
> paths_to_dict(paths)
{ a: { b: { c: null, d: null } } }
>
> paths_to_dict(paths,true)
{ a: { b: { c: '/a/b/c', d: '/a/b/d' } } }
>
dict_to_paths
> dict_to_paths({ a: { b: { c: null, d: null } } })
[ '/a/b/c', '/a/b/d' ]
>
> dict_to_paths({ a: { b: { c: '/a/b/c', d: '/a/b/d' } } })
[ '/a/b/c', '/a/b/d' ]
>
load_from_paths
var paths = [
"/a/b/c",
"/a/b/d"
]
rt =load_from_paths(paths)
> rt.$sdfs_
[
[/] { SP: { sp: '/' } },
[/a/] {},
[/a/b/] {},
[/a/b/c] {},
[/a/b/d] {}
]
> rt.dict()
{ a: { b: { c: null, d: null } } }
>
> rt.dict(true)
{ a: { b: { c: '/a/b/c', d: '/a/b/d' } } }
>
> rt.entries()
[ [ '/a/b/c', null ], [ '/a/b/d', null ] ]
>
> rt.entries(true)
[ [ '/a/b/c', '/a/b/c' ], [ '/a/b/d', '/a/b/d' ] ]
>
METHODS
rt.add_with_pl rt.constructor
rt.del_with_pl rt.dict
rt.entries rt.get_with_pl
rt.is_dir rt.is_file
rt.is_leaf_dir rt.is_nonleaf_dir
rt.k_ rt.path_
rt.paths_ rt.pl_
rt.pls_ rt.rel_dict
rt.rel_entries rt.rel_path
rt.rel_paths rt.rel_pl
rt.rel_pls rt.sp_
rt.to_dir rt.to_file
rt.SP
APIS
{
DFLT_CFG: [Function: DFLT_CFG],
parse_one: {
_parse: [Function: _parse],
parse: [Function: parse],
parse_trim_begin: [Function: parse_trim_begin],
parse_trim_end: [Function: parse_trim_end],
parse_trim_both: [Function: parse_trim_both]
},
paths_to_dict: [Function: paths_to_dict],
dict_to_paths: [Function: dict_to_paths],
load_from_paths: [Function: load_from_paths],
load_from_pls: [Function: load_from_pls],
load_from_dict: [Function: load_from_dict]
}
LICENSE
- ISC