grasp

install npm install -g grasp

Search, replace, and refactor your JavaScript code based on its structure rather than its text

Grasp is a command line utility that allows you to search and replace your JavaScript code - but unlike programs such as grep or sed, it searches the structure behind your code (the abstract syntax tree), rather than simply the text you've written - this allows you to:

Latest blog post: Grasp 0.4.0 released with ES6 support!

Search using CSS style selectors
$ grasp 'if.test[op=&&]' a.js
2:  if (x && f(x)) { return x; }
5:    if (xs.length && ys.length) {
10:  if (x == 3 && list[x]) {
Search using JS code w/ wildcards
$ grasp -e 'return __ + __' b.js
3:  if (x < 2) { return x + 2; }
13:      return '>>' + str.slice(2);
15:  return f(z) + x;
Make complex replacements
$ cat c.js
f(x < y, x == z);
$ grasp bi --replace '{{.r}}+{{.l}}' c.js
f(y+x, z+x);

Demo!

Available commands: grasp, ls, cd, cat, edit, clear, pwd, touch, echo, cp, mv, rm, mkdir, rmdir, |, <, >, >>.

Try one of the examples above. grasp --help for help.