Created
June 9, 2015 14:46
-
-
Save StreetStrider/acf2b870b751e6267487 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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