Skip to content

Instantly share code, notes, and snippets.

@StreetStrider
Created June 9, 2015 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StreetStrider/acf2b870b751e6267487 to your computer and use it in GitHub Desktop.
Save StreetStrider/acf2b870b751e6267487 to your computer and use it in GitHub Desktop.
var isArray = Array.isArray;
module.exports = function strip (ast)
{
ast = ast.filter(filterOnlyLeaves(like));
ast = ast.map(mapOnlyBranches(strip));
return ast;
}
function filterOnlyLeaves (fn)
{
return function (node)
{
if (isArray(node))
{
return true;
}
else
{
return fn(node);
}
}
}
function mapOnlyBranches (fn)
{
return function (node)
{
if (isArray(node))
{
return fn(node);
}
else
{
return node;
}
}
}
function like (term)
{
if (term == null)
{
return false;
}
if (! String(term).trim())
{
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment