🚀 graph-fs
Allow to browse files like a graph where each file or directory is a node.
const {Node} = require("graph-fs");
Instantiate
const directory = new Node("/path/to/directory");
const file = directory.resolve('file.ext');
const sameFile = new Node("/path/to/directory/file.ext");
sameFile === file;
Get infos
myFile.exists;
myFile.is.file;
myFile.is.directory;
myDirectory.is.directory;
myDirectory.is.file;
Path & name
myDirectory.toString();
myDirectory.absolute;
myDirectory.name;
myFile.toString();
myFile.absolute;
myFile.name;
Navigate
const parent = file.parent
const sameParent = file.resolve("..")
parent === sameParent
Read
directory.children;
file.getContent([options = "utf8"]);
Create
const newDirectory = directory.newDirectory("new-directory");
const target = dir.resolve('this/path/does/not/exists');
target.exists;
target.asDirectoryRecursively();
target.exists;
target.is.directory;
Write
const newFile = directory.newFile("newFile.ext", [content]);
file.overwrite(contentString);
Rename
const changedDir = directory.rename('changed');
directory.exists;
changedDir.exists;
Copy
const me2 = directory.copy('me2');
directory.exists;
me2.exists;
Move
const newLocation = directory.move('newLocation');
directory.exists;
newLocation.exists;
Clean
directory.clear()
directory.delete()