dotfs
v0.1.2
Published
Set file paths in dot notation
Downloads
3
Maintainers
Readme
Welcome to DotFS
Welcome to DotFS, a way to browse your filesystem using dot notation (ish). So instead of requiring a file like
require('../../../sampleFolder/anotherFolder/data/package.json
, you can require a file like
df.req('back.back.back.sampleFolder.anotherFolder.data.package.json')
.
Getting Started
Install
To install DotFS, make sure you have NodeJS on your computer. Navigate to your project folder and runs
npm install dotfs --save
Use
To use DotFS, require it like this:
var df = require('dotfs')
You can use any variable for DotFS, but we're going to use df for our examples
Usage
Keywords
To begin with, there are 4 keywords you should know.
current ➡️ ➡️ ➡️ this keeps you in your current directory
back ➡️ ➡️ ➡️ this moves you back one directory
beginning ➡️ ➡️ ➡️ this brings you to the root of your directory
Your route must begin with ones of these keywords (for now). If DotFS doesn't find that your route starts with one of these keywords, it will fill in with a default. The default is set to beginning.
Folders 📁 📁 📁
Folders are supported in DotFS, but not entirely in Node, so be careful. The find
function is really the only one you would want to use folders with.
To target a folder, end your path with .folder
or if that's too much to type, just end it with .f
Example: df.find(current.path.example.f)
returns './path/example/'
Usage
Right now, DotFS has three functions: find, req, and log.
Find function
example : df.find('path.here')
Find will convert your path from DotFS notation to traditional path notation.
df.find('current.src.img.local.test.jpg');
returns './src/img/local/test.jpg'
Req function
example : df.req('path.here')
Req will require the file
df.req('back.back.style.mainApp.style.css');
returns require('../../style/mainApp/style.css');
Req basically does require(something) but in DotFS notation.
Log function*
example : df.log('path.here')
log console.logs the conents of the file you request
This will console log the contents of './current/next/folder/almost/there/setup.json'
Limitations
-As of 0.1.2 and below, you can only use absolute paths for df.req
and df.log
(fix coming soon)
-DotFS currently only supports the...translation of routes. Basically this means that your route might be easer to view/understand, but doesn't make it any quicker for you. We're working on create shorcuts right now, so that if you started your route with 'shorcut1', it would automatically reroute to '/path/to/shorcut1'.
-You have to use dot notation in quotes (sadly 😢) (for now)
Version history
0.1.2 -- Most current version -
So, I found a bug 😞 -- using the df.req
or df.log
function would not work with relative paths because my code is trying to get that file from it's relative path. This includes some better error management for that. Fix coming soon!
0.1 - 0.1.1 Support for folders! 📁 📁 📁 Yay! Just end your path with .f
or .folder
0.0.6
Includes new function called log. df.log('path')
to console log the contents of the file;
0.0.5 - Working version. Includes find
and req
functions.
0.0.1 - 0.0.4 - Do not use DotFS with these versions. They don't do anything. 😀
Coming Soon
-Use relative paths for df.log
and df.req
-Custom shortcuts
-Change phrases for back, current and beginning
-Maybe actually use dot notation instead of a string (probably not)
-Logic in the paths so back3
would return ../../../
instead of having to do back.back.back