New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

tree-manager

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-manager

Display and manage directory tree. Connector for jstree.

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

tree-manager

nodejs connector for jstree library.

To run the example go to example folder run npm install and point your browser to localhost:5000.

Initialization

var TreeManager = require('../lib/treemanager');
var rootDir = __dirname + '/test_dir_root';
var treeManager = new TreeManager(rootDir);

Set the root path whil instantiating the module.

You can change the root directory on the fly by calling treeManager.setRoot(path) with a path as an argument.

Methods

walkDir

Walks down recursivelly the root folder.

Example:

treeManager.walkDir(rootDir, function (err, tree) {
  console.log(tree);
});

Parameters:

  • rootDirectory - absolute path to rd
  • callback - function called on success or error, returns error object or an object with the directory structure

createNode

Creates a new file or folder

Example:

var type = 'file';
var filename = path.join(req.query.id, req.query.text);
treeManager.createNode(filename, type, function (res) {
  console.log(res);
});

Parameters:

  • name - path to a new file or folder
  • type - file or folder
  • callback - function called on success or error, returns error object or new folder or file name.

renameNode

Renames a file or folder

Example:

treeManager.renameNode('some_dir/note.txt', 'note_changed.txt', function (res) {
  console.log(res);
});

Parameters:

  • oldPath - path to the current file or folder
  • newName - new name for the file or folder
  • callback - function called on success or error, returns error object or changed file path

deleteNode

Removes file or folder. Folders are removed recursivelly.

Example:

treeManager.deleteNode('some_dir/notes.txt', function (res) {
  console.log(res);
});

Parameters:

  • nodePath Relative path of the node to be removed
  • callback - function called on success or error, returns error object or path of the removed node

moveNode

Moves node

Example:

treeManager.moveNode('some_dir/notes.txt', 'next_level/other_dir', function (res) {
  res.send(res);
});

Parameters:

  • nodePath Relative path of the node to be moved
  • nodeParent Relative path of the parent target node
  • callback - function called on success returns new path to the node

Tests

To perform tests run npm test in the tree-manager root directory.

TODO

  • 2 option for folder removal - recursive with all subfolders and files and only empty
  • check performance of walkDir function for larger directory structure
  • check uniqueness after renaming and moving - server side
  • write file to example

Keywords

tree

FAQs

Package last updated on 18 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts