Git Product home page Git Product logo

graph-fs's Introduction

❄️ graph-fs

Browse files and directories in a graph.

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

 // create a new directory
const newDirectory = directory.newDirectory("new-directory");

// create a directory recursively
const target = dir.resolve('this/path/does/not/exists');
target.exists; // false
target.asDirectoryRecursively();
target.exists; // true
target.is.directory; // true

Write

// create a new file
const newFile = directory.newFile("newFile.ext", [content]);

// force to write a file, even if it or its parents, still don't exist. It will create the full path to it.
file.overwrite(contentString);

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

graph-fs's People

Contributors

yairopro avatar yoelfaiv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.