Comparing version 1.0.4 to 1.0.5
@@ -10,1 +10,10 @@ const | ||
exports.VDT = vdos.VirtualDirectoryTree; | ||
vdos.VirtualDirectoryTree('./', (vdt) => { | ||
vdt.search('test', (results) => { | ||
console.log('Found ' + results.length + ' items'); | ||
for (var i = 0; i < results.length; i++){ | ||
console.log(results[i].fullPath); | ||
} | ||
}); | ||
}); |
{ | ||
"name": "fsgod", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Secure file sharing, hosting, and transfer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,8 +6,10 @@ | ||
The only component thus far (v 1.0.4) is the Virtual Directory Tree (VDT). | ||
The only component thus far (v 1.0.5) is the Virtual Directory Tree (VDT). | ||
The purpose of this library is to make dynamic managing of any size of file system easy and quick. | ||
##API Example | ||
##API | ||
###VDT | ||
``` | ||
@@ -29,2 +31,34 @@ const fsgod = require('fsgod'); | ||
The `vdt` object that gets passed to the callback in ```fsgod.VDT``` is the Virtual Directory Tree. ```fsgod.VDT``` recursively walks through a specified folder and builds each item into a JavaScript object and passes it back to the user in the callback. For the meantime (v1.0.5), ```fsgod.VDT``` can only be used to read and search file system data and content. If you'd like to help, email me at maui.wowie@tuta.io. | ||
###VDT.search | ||
``` | ||
fsgod.VDT('./', (vdt) => { | ||
var myDirectory = vdt; | ||
myDirectory.search('test', { content: false }, (results) => { | ||
console.log('Found ' + results.length + ' items'); | ||
for (var i = 0; i < results.length; i++){ | ||
console.log(results[i].fullPath); | ||
} | ||
}); | ||
}); | ||
``` | ||
The above code should find file names and directory names that contain the phrase 'test' and print their full paths. | ||
You should notice the second argument takes an object which specifies search options, this argument is optional and simply invoking: | ||
``` | ||
vdt.search('test', (results) => { | ||
console.log(results.length); | ||
}); | ||
``` | ||
will return the search results without any filters. The filter booleans you can assign are | ||
1. `content`: true or false. decides whether or not to search file content for results | ||
2. `names`: true or false. decides whether or not to search file/directory names for results | ||
3. `directories`: true or false. decides whether or not to include directories in results | ||
4. `files`: true or false. decides whether or not to include files on search results | ||
4. `excludes`: Array. excludes results containing any strings in the `excludes` array | ||
##More Info | ||
@@ -36,4 +70,2 @@ | ||
The `vdt` object that gets passed to the callback in ```fsgod.VDT``` is the Virtual Directory Tree. ```fsgod.VDT``` recursively walks through a specified folder and builds each item into a JavaScript object and passes it back to the user in the callback. For the meantime (v1.0.4), ```fsgod.VDT``` can only be used to read data. If you'd like to help, email me at maui.wowie@tuta.io. | ||
| VDT object keys | Usage | Type | | ||
@@ -40,0 +72,0 @@ |:---:|:---:|:---:| |
@@ -69,2 +69,89 @@ (function () { | ||
dir.search = function($term, $options, $cb){ | ||
if(typeof $term !== 'string') throw 'Search Term Must Be A String!'; | ||
if (!$cb) { $cb = $options; $options = {}; } | ||
if ($options.content === undefined) $options.content = true; | ||
if ($options.names === undefined) $options.names = true; | ||
if ($options.directories === undefined) $options.directories = true; | ||
if ($options.files === undefined) $options.files = true; | ||
console.log('Search Options: '); | ||
console.log($options); | ||
var searchTerm = new RegExp($term, 'g'), | ||
excludes = [], | ||
searchesStarted = 0, | ||
searchesFinished = 0, | ||
results = []; | ||
if ($options.excludes) { | ||
for (var i = 0; i < $options.excludes.length; i++){ | ||
if (typeof $options.excludes[i] !== 'string') throw 'All Excludes Must Be A String!'; | ||
else excludes.push(new RegExp($options.excludes[i], 'gi')); | ||
} | ||
} | ||
initSearch(); | ||
function initSearch(){ | ||
find(dir.content); | ||
function find($searchList){ | ||
searchesStarted++; | ||
function isValid(item){ | ||
var valid = true; | ||
for(var i = 0; i < excludes.length; i++ ){ | ||
if ($options.names){ | ||
if (excludes[i].test(item.name)) valid = false; | ||
} | ||
if ($options.content && item.type === 'file'){ | ||
if (excludes[i].test(item.content)) valid = false; | ||
} | ||
} | ||
console.log('The Validity Of ' + item.fullPath + ' Is ' + valid); | ||
return valid; | ||
} | ||
for (var i = 0; i < $searchList.length; i++){ | ||
var added = false; | ||
if ($searchList[i].type == 'file'){ | ||
if ($options.files){ | ||
if ($options.content){ | ||
if (searchTerm.test($searchList[i].content)) { | ||
if (isValid($searchList[i])){ | ||
results.push($searchList[i]); | ||
added = true; | ||
} | ||
} | ||
} | ||
if (!added && $options.names){ | ||
if (searchTerm.test($searchList[i].name)) { | ||
if (isValid($searchList[i])){ | ||
results.push($searchList[i]); | ||
added = true; | ||
} | ||
} | ||
} | ||
} | ||
}else if ($searchList[i].type == 'directory'){ | ||
find($searchList[i].content); | ||
if ($options.directories){ | ||
if (searchTerm.test($searchList[i].name)) { | ||
if (isValid($searchList[i])){ | ||
results.push($searchList[i]); | ||
added = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
searchesFinished++; | ||
if (searchesFinished == searchesStarted){ | ||
$cb(results); | ||
} | ||
} | ||
} | ||
}; | ||
(function () { | ||
@@ -71,0 +158,0 @@ scansStarted++; |
11897
188
73