Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the typedefs and docs for updateTag to match how FXP actually behaves #579

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion docs/v4/2.XMLparseOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,11 @@ Output
**Note**: Unpaired tag can't be used as closing tag e.g. `</unpaired>` is not allowed.
## updateTag

This property allow you to change tag name when you send different name, skip a tag from the parsing result when you return false, or to change attributes.
This method allows you to modify the tag by changing the tag name, modifying its attributes, or completely skip the tag from the parsing result.
* When a string is returned that will be the new tag name.
* Returning `false` or `undefined` will skip this tag from the parsing result.
* Returning `true` will make no changes at all

```js
const xmlDataStr = `
<rootNode>
Expand All @@ -930,4 +934,17 @@ const parser = new XMLParser(options);
const output = parser.parse(xmlDataStr);
```

Output
```json
{
"rootNode": {
"A": {
"#text": "value",
"At": "Home"
},
"At": "Home"
}
}
```

[> Next: XmlBuilder](./3.XMLBuilder.md)
8 changes: 5 additions & 3 deletions src/fxp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ Control how tag value should be parsed. Called only if tag value is not empty
Change the tag name when a different name is returned. Skip the tag from parsed result when false is returned.
Modify `attrs` object to control attributes for the given tag.

@returns {string} new tag name.
@returns false to skip the tag
@returns {string} to change the tag name
@returns {true} to not make any changes
@returns {false} to skip the tag from the parsing result
@returns {undefined} to skip the tag from the parsing result
*/
updateTag: (tagName: string, jPath: string, attrs: {[k: string]: string}) => string | boolean;
updateTag: (tagName: string, jPath: string, attrs: {[k: string]: string}) => string | boolean | undefined;
};
type strnumOptions = {
hex: boolean;
Expand Down