I would like to add an object deep find javascript function to Node-RED in such a way that it is accessible in a function node. Is there any reasonable way to achieve this?
The deep find function is a recursive function that searches deep into an object and returns the sub-set of the object where(if) the search is true. Not especially efficient but is very flexible. Here is the function:
function uibDeepFind(obj, matcher, cb) {
if (matcher(obj)) {
cb(obj)
}
for (let key in obj) {
if (typeof obj[key] === 'object') {
uibDeepFind(obj[key], matcher, cb)
}
}
}
matcher and cb are, themselves, functions that you pass in.
Well, you can certainly add a function there to global. However, that would require everyone who wants to use it to add it themselves. What I wanted was a way to make something available to anyone who has installed uibuilder without having to make them do something extra. Rather like node-red plugins. But for function nodes.
I did a search and could not find it but I have a vague memory of someone that created a plugin shell that would actually use the content of a function node as its source.