Add custom node post-processing support #642
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The purpose of this is to pass a list of processors that takes nodes, once xml2js has created them, and performs custom post-processing on them.
I was able to get some processing functionality working by writing a validator that manipulated the data but that seemed unintuitive and currently you can only have one validator function per parser config.
This isn't a breaking change and I've added a test case to cover it. The defaults set the array of processors to
null
so it won't affect anyone unless they explicitly add processors in.I appreciate that the two-function way I've written might not be a bit too verbose. If you prefer I can change it to be a simple array of functions. For an example of this, here's the sample processor I put in the readme:
And here's the alternative approach:
Let me know if this is preferable, or if there are any other changes you'd like to see on this.