POSIX/win32 path strings to POJO tree
npm install @kettek/filepaths-to-treeObjectMake creates a new tree object from an array of POSIX or win32 style paths.
ObjectInsert inserts the given path into the root object and assigns the value to the end node.
ObjectRemove removes the given path from the root object. Also removes any branches that are made empty during this process.
ObjectFind returns the tree branch, end node value, or undefined from the given path in the tree.
Array.<string>SplitPath returns an array of strings representing a path's structure split by forward or back slashes.
anyObjectMake creates a new tree object from an array of POSIX or win32 style paths.
Returns: Object -
The resulting tree.
| Param | Type | Description |
| --- | --- | --- |
| paths | Array.<string> |
An array of POSIX or win32 style paths to build the tree object.
|MakeCallback | A optional callback to assign to the end node of the path.
|Example
``js`
// returns { a: { b: { c: 'a/b/c', d: 'a\\b\\d', e: 'a\\b/e' } }, b: { c: { a: 'b/c\\a' } } }
Make(['a/b/c', 'a\\b\\d', 'a\\b/e', 'b/c\\a'], p => p)
ObjectInsert inserts the given path into the root object and assigns the value to the end node.
Returns: Object -
The root tree object.
| Param | Type | Description |
| --- | --- | --- |
| root | Object |
The root tree object to grow to fit the path.
|string | The POSIX or win32 path to create as a branch.
|any | The value to set the end of the branch to.
|Example
`js`
// returns { my: { mixed: { path: 'something' } } }
Insert({}, '/my\\mixed/path', 'something')
ObjectRemove removes the given path from the root object. Also removes any branches that are made empty during this process.
Returns: Object -
The root tree object.
| Param | Type | Description |
| --- | --- | --- |
| root | Object |
The root tree object to grow to fit the path.
|string | The POSIX or win32 path to remove from the tree.
|Example
`js``
// returns { a: { '1': 'a/1', '2': 'a/2' }, b: { '1': 'b\\1' } }
let t = Make(['a/1', 'a/2', 'b\\1'])
// returns { a: { '2': 'a/2' }, b: { '1': 'b\\1' } }
Remove(t, 'a/1')
// returns { a: { '2': 'a/2' } }
Remove(t, 'b/1')
ObjectFind returns the tree branch, end node value, or undefined from the given path in the tree.
Returns: Object -
The tree branch, end value, or undefined.
| Param | Type | Description |
| --- | --- | --- |
| root | Object |
The root tree object to grow to fit the path.
|string | The POSIX or win32 path to remove from the tree.
|Array.<string>SplitPath returns an array of strings representing a path's structure split by forward or back slashes.
Returns: Array.<string> -
An array of paths separated by / or \\.
| Param | Type | Description |
| --- | --- | --- |
| path | string |
The POSIX or win32 path to remove from the tree.
|anyany - The value to assign to the given entry.
| Param | Type | Description |
| --- | --- | --- |
| fullpath | string |
The full path of the given entry.
|
*
© 2022 Ketchetwahmeegwun T. Southall