react-ecmascript
Version:
A script which transform React and ReactDOM into native Ecmascript modules to be used in browsers which support Ecmascript modules and module loading
25 lines (20 loc) • 425 B
JavaScript
module.exports = function walk(item, checks = []) {
const check = checks.shift();
if (!check) {
return item;
}
let found = false;
if (Array.isArray(item)) {
for (let currentItem of item) {
if (check(currentItem)) {
found = currentItem;
break;
}
}
} else if ('object' === typeof item) {
found = check(item);
}
if (found) {
return walk(found, checks);
}
};