mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 23:29:35 +02:00
23 lines
463 B
JavaScript
23 lines
463 B
JavaScript
import objectScan from 'object-scan'
|
|
|
|
const createFindInTree = (needles) => {
|
|
const scanner = objectScan(needles, {
|
|
filterFn: ({ value, parents, matchedBy, context }) => {
|
|
matchedBy.forEach((needle) => {
|
|
context[needle].push([value, parents])
|
|
})
|
|
}
|
|
})
|
|
|
|
return (haystack) => {
|
|
const context = Object.create(null)
|
|
needles.forEach((needle) => {
|
|
context[needle] = []
|
|
})
|
|
return scanner(haystack, context)
|
|
}
|
|
}
|
|
|
|
export {
|
|
createFindInTree,
|
|
}
|