Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function filterPaths(
data: NonNullable,
query: string,
parent: JSONArray = ['root']
): JSONArray {
if (JSONExt.isArray(data)) {
return data.reduce((result: JSONArray, item: JSONValue, index: number) => {
if (item && typeof item === 'object' && objectIncludes(item, query)) {
return [
...result,
[index, ...parent].join(','),
...filterPaths(item, query, [index, ...parent])
];
}
return result;
}, []) as JSONArray;
}
if (JSONExt.isObject(data)) {
return Object.keys(data).reduce((result: JSONArray, key: string) => {
let item = data[key];
if (
item &&