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

reprrepr

v0.0.12

Published

#Read Evaluate Print Repeat

Downloads

4

Readme

###READ ###EVALUATE ###PRINT ###REPEAT ###READ ###EVALUATE ###PRINT ###REPEAT

#Read Evaluate Print Repeat

A Javascript REPL with a customizable scope

##Features

###Multiple Languages reprrepr currently supports the folowing languages through use of the --language flag:

###Isolated Scope reprrepr executes in an isolated scope with most top level objects stripped out. You may define your own custom scope using the --set-scope flag (see below for more).

###Custom Rendering reprrepr needn't simply render to the console. Define your own custom render function with the --set-renderer flag (see below for more).

###Proxied Evaluation reprrepr isn't limited to simply evaluating the built in languages, or even on your local machine. Proxy your input with the --set-proxy flag (see below for more).

###Web Socket REPL reprrepr can host a repl using the --host flag (see below for more).

##Installation

npm install -g reprrepr

##Usage

###View Help

repr --help

###Open a Javascript REPL

repr

Note: Quit using Ctrl + c.

###Open a Lispyscript REPL

repr --language lispyscript

###View available languages

repr --languages

###Evaluate Javascript inline

repr --eval "1 + 1;"

###Evaluate code before starting a repl

repr --pre "var a = 1;"

###Evaluate piped code using an empty --eval flag

echo "1 + 1" | repr --eval

###Evaluate A Javascript file

repr --file javascript.js

###Evaluate A Lispyscript file

repr --file --language lispyscript lispyscript.lsjs

###Open a REPL with specified scope module

repr --set-scope scope.js

The scope module should export an object similar to the following:

module.exports = {
  Math : Math
}

###Open a REPL with specified renderer module

repr --set-renderer renderer.js

The renderer module should export a function similar to the following:

module.exports = function(input, output){
  return output;
};

###Proxy input through an external module

repr --set-proxy proxy.js

The proxy module should export a function similar to the following:

module.exports = function(input){
  return Promise.resolve([input, eval(input)]);
}

It should take an input and return a promise resolved an array of length 2; the first value must be the original input, the second value should be the evaluated input.

Note: Setting the proxy will override the language settings but not the renderer settings.

###Host a server at 127.0.0.1:8080

repr --host 8080

Multiple parties can connect to this server and send input over a socket. Output will be distributed to all connected parties.

###Flags can be mixed and matched (where it makes sense)

repr --language es6 \
--set-scope scope.js\
--verbose \
--errors \
--file input.es6.js > output.js

Note: Renderer, scope, and proxy modules must be written in Javascript, even if the REPL's language is set to something different.

BONUS!: Many languages can now be easily converted into javascript!

##.reprrc You can define a .reprrc file with pre-defined settings.

{
  "verbose"     : true,
  "renderer"    : "renderer.js",
  "language"    : "lispyscript",
  "scope" : "scope.js",
  "proxy"       : "proxy.js",
  "host"        : 8080
}

Note: The .reprrc is a json file and .reprrc.json can be used as well.

The following properties are available in the .reprrc file:

  • verbose -- show verbose console output
  • errors -- show errors in console output
  • renderer -- similar to --set-renderet flag
  • language -- similar to --language flag
  • scope -- similar to --set-enviornmet flag
  • proxy -- similar to --set-proxy flag
  • host -- similar to --host flag
  • eval -- similar to --eval flag
  • pre -- similar to --pre flag

##Advanced Usage Examples

###Access history from within your repl

  • 1 - Set up a module that exports a history array.

####history.js

var history = [];
module.exports = history;
  • 2 - Create an renderer that adds inputs to the history array.

####render.js

var history = require('./history');
var render = function(input, output){
  history.push(input);
  history.push(output);
  return output;
};
module.exports = render;
  • 3 - Create an scope with functions to access history

####scope.js

var history = require('./history');
var scope = {
  input:function(index){
    return history[2 * index];
  },
  output:function(index){
    return history[2 * index + 1];
  },
  history:history
}
  • 4 - Run with custom Flags
repl --set-scope scope.js --set-render render.js
> 1 + 1
2
> 3 + 2
5
> output(0);
2
> input(1)
3 + 2
> history[4]
output(0);

Note : Be careful when your repl leaks into its outer scope like this. It may lead to unintended side effects.

  • 4 (alternative) - Alternatively, you can instead set these in a .reprrc file like so:

####.npmrc

{
  "scope" : "scope.js",
  "render"      : "render.js"
}

###READ ###EVALUATE ###PRINT ###REPEAT ###...