redoc/src/utils/test-utils.ts
Oprysk Vyacheslav 35418b1569
chore: migrate from babel to esbuild loader (#1848)
* chore: migrate from babel to esbuild loader

* fix cypress tests
2022-01-25 15:50:28 +02:00

30 lines
583 B
TypeScript

import { objectHas, objectSet } from './object';
function traverseComponent(root, fn) {
if (!root) {
return;
}
fn(root);
if (root.children) {
for (const child of root.children) {
traverseComponent(child, fn);
}
}
}
export function filterPropsDeep<T extends object>(component: T, paths: string[]): T {
traverseComponent(component, comp => {
if (comp.props) {
for (const path of paths) {
if (objectHas(comp.props, path)) {
objectSet(comp.props, path, '<<<filtered>>>');
}
}
}
});
return component;
}