filenavigator
v1.0.8
Published
A simple CommonJS/ES module made to easely navigate in the depth of folders
Downloads
5
Readme
📝 Table of Contents
🧐 About
The aim behind this was to make life easier when you use way too much paths in your project, and when their not from the same folder, for instance it's very usefull with EJS.
🏁 Getting Started
Installing
Just install the packet with npm :
$ npm install filenavigator
🔧 Running the tests
Like for each npm package :
$ npm test
🎈 Usage
/* Imagine you have a folder like that:
──┮ ..
├──╼ LICENSE
├──╼ README.md
├──┮ docs
│ └──╼ ico.svg
├──╼ package.json
└──┮ src <-- You're here
├──╼ index.js
└──╼ test.js
*/
const fs = require("fs"),
fn = require("filenavigator"),
parentDir = fn.Dir.from(".."), // .from is needed if this came from a real path, here we get the parent folder of the script
parentDirRoot = parentDir.asRoot(); // Here we make a copy of parentDir but his paths have removed the part from the parent ("..")
// Then you can navigate in the directory:
const ico = fs.readFileSync(parentDir.docs.ico);
for (let child of parentDir) console.log(child);
// You can also visualize the directory:
console.log(parentDir.tree);
🚀 Deployment
Build and tested on a linux, no certification this will work on windows but I think it's working on, anyway if it doesn't report here.
🚀 Limitations
There is no support for file with the same name but not the same extension. Beside that it's good to know that module can slow you're programm if you scan bif folder without setting a depth limit. The current transformation to turn file name in object key is like that:
index.js --> index // For normal name
.vscode --> _vscode // For hidden unix name
hello.world.txt --> hello_world // For name with multilple dots
⛏️ Built Using
- NodeJs - Server Environment
✍️ Authors
- @loucas - Idea & Initial work