Skip to content

Commit

Permalink
Add tree-math to foreach.
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Murphy-Skvorzov committed Sep 28, 2015
1 parent 84d3eb8 commit 966de40
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions bin/foreach.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ function keyvals(dict, callback){

function setpath(subject,path,value){
var c=path.length;
var ans = path.reduce(function(s,n){return s[n]=--c?(s[n]||{}):value;var after=s[n];},subject);
path.reduce(function(s,n){return s[n]=(--c?(s[n]||{}):value);},subject);
}
function getpath(subject,path){
return path.reduce(function(s,n){if(s!==undefined)return s[n];},subject);
}
var tm = require('tree-math');

function find(data, options, callback) {
if (typeof(options)==='function'){
callback = options;
Expand Down Expand Up @@ -68,8 +70,8 @@ var source = require('./clean')(process.stdin);
source.on('comment', function(c){console.log(c);});
eventHandlers.forEach(function(tuple){
var event = tuple[0].toLowerCase();
var code = Function('require','emit','keyvals','setpath','getpath','find','flatten', 'record', 'lineNumber', 'line', 'recordNumber', tuple[1])
.bind(null,req, emit, keyvals , setpath , getpath , find , flatten);
var code = Function('require','emit','keyvals','setpath','getpath','tm','find','flatten', 'record', 'lineNumber', 'line', 'recordNumber', tuple[1])
.bind(null,req, emit, keyvals , setpath , getpath , tm , find , flatten);
code.name = event;
if (['beg','begin','start','beginning'].indexOf(event)!== -1) code();
else source.on(event, code);
Expand Down
2 changes: 1 addition & 1 deletion bin/foreach.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ All standard nodejs functions are available and in addition:

* `find(dict,{options},callback(path,value){....})` Find all paths in a dictionary. Useful for converting trees into tabular form. Options are: `{maxdepth:3,prefix:["each","row","starts","with"]}`


* `tm` - the tree-math library.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jline",
"version": "0.0.39",
"version": "0.0.40",
"description": "Sort, grep and join files where every line is JSON.",
"main": "index.js",
"bin": {
Expand Down Expand Up @@ -58,7 +58,7 @@
"dependencies": {
"docopt": "^0.4.1",
"split": "^0.3.0",
"tree-math": "0.0.16",
"tree-math": "0.0.17",
"ya-csv": "^0.9.4"
}
}

0 comments on commit 966de40

Please sign in to comment.