Skip to content

Instantly share code, notes, and snippets.

@jeremyrajan
Created July 22, 2016 07:02
Show Gist options
  • Save jeremyrajan/eb4d2ce1ed16af21d4b53e8321802b88 to your computer and use it in GitHub Desktop.
Save jeremyrajan/eb4d2ce1ed16af21d4b53e8321802b88 to your computer and use it in GitHub Desktop.

Revisions

  1. jeremyrajan created this gist Jul 22, 2016.
    84 changes: 84 additions & 0 deletions candy.js
    Original 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) => {

    };