Comparing version 1.0.7 to 1.0.8
@@ -9,2 +9,2 @@ const | ||
exports.VirtualDirectoryTree = vdos.VirtualDirectoryTree; | ||
exports.VDT = vdos.VirtualDirectoryTree; | ||
exports.VDT = vdos.VirtualDirectoryTree; |
{ | ||
"name": "fsgod", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Secure file sharing, hosting, and transfer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
##FSGOD (Alpha) | ||
## FSGOD (Alpha) | ||
A service for securely managing, transfering, collaborating, and hosting content on your local network | ||
The only component thus far (v 1.0.7) is the Virtual Directory Tree (VDT). | ||
The only component thus far 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 | ||
## API | ||
###VDT | ||
### VDT | ||
@@ -32,5 +32,5 @@ Recursively step through a file tree to create a 'Virtual File Tree' which allows for quicker data processing and greater control over your file system | ||
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.7), `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. | ||
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, `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 | ||
### VDT.search | ||
@@ -63,4 +63,6 @@ Every directory in the VDT (including the root/target directory) has a search method. The search method uses regular expressions to locate any item containing the string passed in the first argument. | ||
``` | ||
Will return the search results without any filters. The filter options you can assign are | ||
Will return the search results without any filters. | ||
The filter options you can give to the object are | ||
| Filter | Type | Usage | | ||
@@ -72,17 +74,25 @@ |:---:|:---:|:---:| | ||
| directories | Boolean | Decides whether or not to include directories in results | | ||
| excludes | Boolean | Any search results containing a string in the 'excludes' array will be removed | | ||
| excludes | Array | Any search results containing a string in the 'excludes' array will be removed | | ||
## Virtual Directory | ||
##More Info | ||
Each directory in the vdt callback is it's own Virtual Directory Tree with the same methods as the intial target directory | ||
| Function | Arguments | Usage | | ||
| Key | Type | Usage | | ||
|:---:|:---:|:---:| | ||
| VDT or VirtualDirectoryTree | url: the path to the directory you'd like to operate, done: to be called when VDT is done getting the directory | fsgod.VDT(urlToFolder, function(vdt){ }) | | ||
| content | Array | An array of both directories (VDT's) and files | | ||
| name | String | The name of the file or directory | | ||
| type | String | Will let you know if its a directory or file | | ||
| fullPath | String | The full path to the item | | ||
| size | Integer | Size of the item in bytes | | ||
| search | Function | Search in and under the directory for a search string | | ||
| VDT object keys | Usage | Type | | ||
## Virtual File | ||
| Key | Type | Usage | | ||
|:---:|:---:|:---:| | ||
| content | The content of the item, if it's a directory it will be an array of other items. If it's a file it will be it's file content | Array or String | | ||
| name | The name of the file or directory | String | | ||
| type | Will let you know if its a directory or file | String | | ||
| fullPath | The full path to the item | String | | ||
| size | Size of the item in bytes | Integer | | ||
| content | String | File contents | | ||
| name | String | File name | | ||
| type | String | Will let you know if it's a directory or file | | ||
| fullPath | String | The full path to the item | | ||
| size | Integer | Size of the item in bytes | |
@@ -98,81 +98,2 @@ (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; | ||
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 () { | ||
@@ -198,2 +119,82 @@ scansStarted++; | ||
VirtualDirectory.prototype.search = function($term, $options, $cb){ | ||
var dir = this; | ||
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; | ||
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 end() { | ||
@@ -200,0 +201,0 @@ $done(VDT); |
96
13150