scriptie-talkie

Makes your code tell you what the intermediate results are when executing a script.

scriptie-talkie

Makes your code tell you what the intermediate results are when executing a script.

try it in the browser

var a = 3;
 
= a + 1;
a++;
 
var b = 2;
= b + a;

npm install scriptie-talkie

(Add -g to install as global command line tool)

scriptie-talkie path/to/script.js

Prints the highlighted code of script.js with intermediate results.

curl https://raw.github.com/thlorenz/ansicolors/master/ansicolors.js | scriptie-talkie

Prints the highlighted code of ansicolors.js with intermediate results.

Note that in this case require statements cannot be resolved.

/**
 * Evaluates all snippets in the given script and calls opts.write with the result.
 * 
 * @name exports
 * @function
 * @param script {String} The String to evaluate.
 * @param scriptPath {String} The path to the script (important to resolve require statements)
 * @param opts {Object} { 
 *    toLines: function(code:String) -> [String] - to split script into lines -- uses cardinal syntax highlighter by default
 *    write  : function(result:String) - to be called to write the result -- default console.log
 *    diff   : { joinLinesAt: at what point is diff compacted to one line               -- default 20
 *             , maxLineLength: at which length is a diff line cut of with an ellipsis  -- default 380
 *             }
 */
var talk    =  require('scriptie-talkie')
  , fs      =  require('fs');
  ,  script =  fs.readFileSync(scriptPath, 'utf-8');
 
talk(script, scriptPath, { write: console.error, { diff: { joinLinesAt: 80 } });

scriptie-talkie does work in the browser as long as a vm and Buffer module is available. Additionally the presence of a process with process.browser = true is essential.

The easiest way to build an application that uses sciptie-talkie via browserify as I did in this example. The above mentioned live sample was built like that.

var o = { a: 1 };
 
o.= 2;

var a = 3;
 
+ b;
 
var b = 2;
 
console.log(b.hello());

var a = 1;
foo();
 
function foo () {
  return a++;
}
foo() + 1;