1.1.1 • Published 10 months ago

graph-fs v1.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
10 months ago

plot

Please, star on github if you like this package. ⭐️


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

Path, name & extension

const file = new Node(__filename);
file.toString(); // "/path/to/file.js"
file.basename; // "file.js"
file.extension; // "js"

Navigate

const parent = file.parent;
const notes = file.resolve("notes.txt");
const children = directory.children; // children Node[]
const descendants = directory.getDescendants; // All descendants nodes flattened

Read

const content = file.getContent(); // accepts fs options as parameter

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.asDirectory();
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

Breaking changes from v0 to v1:
- .path is a string. - .name is now .basename. - .descendants is now .getDescendants() - .asDirectoryRecursively() is now .asDirectory()

1.1.1

10 months ago

1.0.2

12 months ago

1.1.0

10 months ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago