Skip to content

Commit

Permalink
+=getpath and setpath
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Murphy-Skvorzov committed Aug 13, 2015
1 parent 143df7e commit 516122b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions bin/foreach.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ function keyvals(dict, callback){
Object.keys(dict).forEach(function(k){callback(k,dict[k]);});
}

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

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', 'record', 'lineNumber', 'line', 'recordNumber', tuple[1])
.bind(null,req, emit, keyvals);
var code = Function('require','emit','keyvals','setpath','getpath', 'record', 'lineNumber', 'line', 'recordNumber', tuple[1])
.bind(null,req, emit, keyvals , setpath , getpath);
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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jline",
"version": "0.0.37",
"version": "0.0.38",
"description": "Sort, grep and join files where every line is JSON.",
"main": "index.js",
"bin": {
Expand Down

0 comments on commit 516122b

Please sign in to comment.