Created
July 22, 2016 07:02
-
-
Save jeremyrajan/eb4d2ce1ed16af21d4b53e8321802b88 to your computer and use it in GitHub Desktop.
Revisions
-
jeremyrajan created this gist
Jul 22, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,84 @@ const entityTypes = ['d', 'f', 't', 'z']; /* properties Type Name Path Content */ const data = []; /* data = [{ type: 'd', name: 'c', path: '/c', children: [{ type: 'f', name: 'myfolder', path: '/c/myfolder', children: [{ type: 't', name: 'textfile', path: '/c/myfolder/textfile', content: 'My Content' }] }] }] */ const findParent = (path) => { const pathArr = path.split('/'); const retPath = ''; let i = 0; let currentParent = data; // const name = pathArr.pop(); // /c/myfolder => folder while(!pathArr.length) { name = pathArr.shift(); // remove the first element the array one by one currentParent.forEach((d) => { if (d.name === name) { retPath = d if (!!d.children) { currentParent = d.children; } else { return 'No Children, cant insert'; } } }); if () } }; const create = (type, name, path) => { if (type === 'd') path = `/${name}`; // create the item const item = { type: type, path: path, name: name }; // if it is a text file, then setup content if (item.type === 't') item['content'] = ''; if (item.type === 'f' || item.type === 'd' || item.type === 'z') item['children'] = []; }; const delete = (path) => { }; const move = (sP, Dp) => { }; const createContent = (path, name, content) => { }; const writeToFile = (path, content) => { };