Hello coin-parser

coin parser is a generic json opening scheme. The contents of the json must be coins. A coin is defined as the following

{
    "head":"node name",
    "description":"suggestion as to what node contents are (tail)",
    "tail":"any content, function, object etc"
}

Here is the parser

//////////// Node Parser
//
//  tail file types
//  string -> function
//  object -> ?
//
//
    const readline = require('readline');
    const fs = require('fs');
    const rl = readline.createInterface(process.stdin, process.stdout);
    const prompt = 'CoinParser'
    rl.setPrompt(''+prompt+'> ');
    rl.prompt();
    var cache = {
      tails:[],heads:{},tools:{map:function(fn){console.log(fn);for(var key=1;arguments[key];key++){fn(arguments[key]);};}}
    };
    var loadJSON = function(file_location, callback){
      fs.readFile(file_location, function (err, data) {
         if (err) {
          console.log("error");
             return console.error(err);
         }
         console.log("callback(data)");
         callback(data);
      });
    }
    var open_chest = function(response){
        var api_handle = JSON.parse(response.toString())["head"];
        console.log("Loading API " + api_handle);
        var commands = JSON.parse(response.toString())["tail"];
        for(var prop in commands)
        {
            var coin = commands[prop];
            var tail  = (typeof coin.tail==='string')?new Function( coin.tail ):coin.tail;
            cache.tails.push({description:coin.description,key:coin.head,payload:tail});
            cache.heads[coin.head] = cache.tails.length - 1;
        }
        // ===========================
        rl.on('line', (line) => {
            var input =line.trim().split(" ");
            var arguments = input.slice(1).join(" ");
            var command = input[0];
            switch(command){
              case 'heads':
                console.log(cache.heads);
                break;
              case 'tails':
                console.log(cache.tails);
                break;
              case 'exit':
                console.log('Have a great day!');
                process.exit(0);
                break;
              default:
                if(typeof cache.heads[input[0]] !== "undefined"){
                  var key = cache.heads[input[0]];
                  console.log(cache.tails[key].key+"("+arguments+")");
                  if(input[1]=="description"){
                    console.log("*"+cache.tails[key].description);
                  }else{
                    console.log("=>");
                    if(typeof cache.tails[key].payload === "function"){
                      console.log(cache.tails[key].payload.apply(cache,arguments.split(" ")));}
                    else{
                      console.log(cache.tails[key].payload);}
                  }
                }else if(command==="new"){
                  if(typeof input[1]==="undefined" || typeof input[2]==="undefined" ){
                    console.log("Missing parameters for new.");

                  }else{
                    var new_top_level=input[1], new_arguments=arguments.split(" ").splice(1).join(" ");

                    cache.tails.push({key:input[1],payload:new Function(new_arguments)});
                    cache.heads[input[1]] = cache.tails.length-1;
                  }
                }else if(true){
                  console.log(cache);
                }else{
                  console.log("nossing!");
                }
              break;
            }

            rl.setPrompt(''+prompt+'> ');
            rl.prompt();
        }).on('close', () => {
            console.log('Have a great day!');
            process.exit(0);
        });
        // ===========================
    };
    var api = process.argv[2];
    loadJSON(api,open_chest);
    //
    //
    //
    //
    //
    ////////////