graph-fs

    0.0.10 • Public • Published

    🚀 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; // true (same instance)

    Get infos

    myFile.exists; // boolean
    
    myFile.is.file; // true
    myFile.is.directory; // false
    
    myDirectory.is.directory; // true
    myDirectory.is.file; // false

    Path & name

    myDirectory.toString(); // "/path/to/directory/"
    myDirectory.absolute; // "/path/to/directory"
    myDirectory.name; // "directory"
    
    myFile.toString(); // "/path/to/file.ext"
    myFile.absolute; //   "/path/to/file.ext"
    myFile.name; // "file.ext"

    Navigate

    const parent = file.parent
    const sameParent = file.resolve("..")
    parent === sameParent // true

    Read

    directory.children; // Node[] of files and directories
    file.getContent([options = "utf8"]); // string

    Create

    directory.newFile("newFile.ext", [content]); // Node instance
    directory.newDirectory("new-directory"); // Node instance

    Rename

    const changedDir = directory.rename('changed'); // Node instance
    directory.exists; // false
    changedDir.exists; // true

    Copy

    const me2 = directory.copy('me2'); // Node instance
    directory.exists; // true
    me2.exists; // true

    Move

    const newLocation = directory.move('newLocation'); // Node instance
    directory.exists; // false
    newLocation.exists; // true

    Clean

    directory.clear() // delete all what's inside the directory
    directory.delete() // delete the directory

    Install

    npm i graph-fs

    DownloadsWeekly Downloads

    14

    Version

    0.0.10

    License

    MIT

    Unpacked Size

    12.3 kB

    Total Files

    10

    Last publish

    Collaborators

    • yairopro