npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coin-parser

v0.0.2

Published

Parse a json file for into a commandline interface.

Downloads

4

Readme

//////////// Node Parser
    //
const readline = require('readline');
const fs = require('fs');
const rl = readline.createInterface(process.stdin, process.stdout);
const prompt = 'CoinParser'

    rl.setPrompt(''+prompt+'> ');
rl.prompt();
// you can always expect two things
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){
  // console.log("loadJSON");
  fs.readFile(file_location, function (err, data) {
     if (err) {
      console.log("error");
         return console.error(err);
     }
     console.log("callback(data)");
     callback(data);
     // console.log("Asynchronous read: " + data.toString());
  });
}
var open_chest = function(response){
    // console.log(response.toString());
    var api_handle = JSON.parse(response.toString())["head"];
    console.log("Loading API " + api_handle);
    var commands = JSON.parse(response.toString())["tail"];
    // console.log(commands);
    for(var prop in commands)
    {
        var coin = commands[prop];
        var tail  = new Function(coin.tail);
        cache.tails.push({description:coin.description,key:coin.head,payload:tail});//{key:input[1],payload:new Function(input.slice(2).join(" "))}
        // cache.tails.push({new Function(coin.tail)});
        cache.heads[coin.head] = cache.tails.length - 1;
        // console.log("working");
    }

    // ===========================
    rl.on('line', (line) => {
        var input =line.trim().split(" ");
        var arguments = input.slice(1).join(" ");
        // console.log(arguments);
        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:
            // console.log(cache.tails);
            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("=>"+cache.tails[key].payload.apply(cache,arguments));
                console.log('payload -> '+cache.tails[key].payload);
                console.log('typeof input -> '+typeof input);
                console.log('typeof arguments -> '+typeof arguments);
                console.log("=>");
                console.log(cache.tails[key].payload.apply(cache,arguments.split(" ")));
              }
              // cache.tails[key](arguments);
            }else if(command==="new"){
              if(typeof input[1]==="undefined" || typeof input[2]==="undefined" ){
                console.log("Missing parameters for new.");

              }else{
                // var value = commands[prop];
                console.log(typeof arguments.split(" ")[1]);
                // console.log(input);
                cache.tails.push({key:input[1],payload:new Function(arguments.split(" ")[1])});
                // console.log(arguments.split(" "));
                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];
// if(typeof api === "undefined"){
  loadJSON(api,open_chest);
  // rl.setPrompt(''+prompt+'> ');
// }
// console.log("Exit");
    //
////////////