![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
treeify-paths
Advanced tools
Provide a list of file names:
And recieve a directory-like tree:
Useful when converting a list of file names into a nested UL/LI tree. Nice for site maps, etc.
Install it with NPM:
npm install --save treeify-paths
import treeifyPaths from "treeify-paths";
If you are not using NPM, install the library by downloading the source file and including it in your project:
curl -o treeify-paths.js "https://raw.githubusercontent.com/khtdr/treeify-paths/master/treeify-paths.js"
let treeify_paths = require("./treeify-paths").default;
This module provides a function treeifyPaths
that takes a list of file names and returns a directory-like tree.
import treeifyPaths from 'treeify-paths';
console.log(JSON.stringify(treeifyPaths([
'about.html',
'careers',
'careers/job-1.html',
'careers/job-2.html',
'to/some/page.aspx',
]), null, 3);
{
"path": "",
"name": "",
"children": [
{
"path": "about.html",
"name": "about.html",
"children": []
},
{
"path": "careers",
"name": "careers",
"children": [
{
"path": "careers/job-1.html",
"name": "job-1.html",
"children": []
},
{
"path": "careers/job-2.html",
"name": "job-2.html",
"children": []
}
]
},
{
"path": "to",
"name": "",
"children": [
{
"path": "to/some",
"name": "",
"children": [
{
"path": "to/some/page.aspx",
"name": "page.aspx",
"children": []
}
]
}
]
}
]
}
You may pass in a list of path
/context
pairs. The context is available in the result.
import treeifyPaths from 'treeify-paths';
console.log(JSON.stringify(treeifyPaths([
['about.html', {admin:false}],
['careers', {admin:false}],
['careers/job-1.html', {admin:false}],
['careers/job-2.html', {admin:false}],
['to/some/page.aspx', {admin:true}],
]), null, 3);
The context is available on the result:
{
"path": "about.html",
"name": "about.html",
"children": [],
"ctx": { "admin": false }
}
By default:
case-sensitive
There are options for overridding this:
import treeifyPaths from "treeify-paths";
treeifyPaths([], {
caseInsensitive: true, // default false
directoriesFirst: true, // default false
directoriesLast: true, // default false
});
The mocha tests have many examples
> npm run test
treeifyPaths([...arguments])
arguments: none
✔ should return an empty object
arguments: empty list
✔ should return an empty object
arguments: list with a single file
✔ should return a single file
✔ should ignore leading slashes
✔ should return with nested children
arguments: multiple file names
✔ should return with nested children
✔ should ignore perimeter slashes and empty or redundant entries
✔ should alphabetize
✔ should alphabetize case-sensitve
✔ should not respect directories
✔ should ignore duplicates
✔ should be able to target directories
12 passing (7ms)
FAQs
list of file names becomes a tree of file descriptions
We found that treeify-paths demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.