allow custom functions in filters

This commit is contained in:
2020-07-03 14:36:39 +02:00
parent dab2b9a852
commit 0dab4976ae
4 changed files with 42 additions and 2 deletions

View File

@ -252,3 +252,30 @@ test ('recursive filter carry field', (t) => {
}
]);
});
test ('recursive filter custom function', (t) => {
const to_filter = [
{
name: 'foo',
children: [
{ name: 'bar' },
{ name: 'baz' },
{ foo: 'bar' }
]
}
];
const res = util.recursive_filter (
to_filter,
[ { function: (elem) => elem.name === 'foo bar' } ],
'children',
[ 'name' ]
);
t.deepEqual (res, [
{
name: 'foo',
children: [ { name: 'bar' } ]
}
]);
});