Sha256: fe7ab2154193d91ef1479a6b84fc587584a5acd8d99f5237777c9cbca538409b
Contents?: true
Size: 1.15 KB
Versions: 11
Compression:
Stored size: 1.15 KB
Contents
function traverse(root, options) { "use strict"; options = options || {}; var pre = options.pre; var post = options.post; var skipProperty = options.skipProperty; function visit(node, parent, prop, idx) { if (!node || typeof node.type !== "string") { return; } var res = undefined; if (pre) { res = pre(node, parent, prop, idx); } if (res !== false) { for (var prop in node) { if (skipProperty ? skipProperty(prop, node) : prop[0] === "$") { continue; } var child = node[prop]; if (Array.isArray(child)) { for (var i = 0; i < child.length; i++) { visit(child[i], node, prop, i); } } else { visit(child, node, prop); } } } if (post) { post(node, parent, prop, idx); } } visit(root, null); }; if (typeof module !== "undefined" && typeof module.exports !== "undefined") { module.exports = traverse; }
Version data entries
11 entries across 11 versions & 4 rubygems