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

Allow coercion of XML node attribute values #17

Open
taveras opened this issue Dec 14, 2017 · 1 comment
Open

Allow coercion of XML node attribute values #17

taveras opened this issue Dec 14, 2017 · 1 comment

Comments

@taveras
Copy link
Contributor

taveras commented Dec 14, 2017

We currently require our consumers to coerce and validate their attributes themselves within their converter callbacks.

It may be beneficial to coerce the type of each XML node attribute value for use within a converter callback.

e.g.,

<Party>
  <Person name="Mary" age="20"  ready="true" />
</Party>
const xmlToReact = new XMLToReact({ Person: convertPerson });

function convertPerson (attributes) {
   typeof attributes.name; // 'string'
   typeof attributes.age; // 'string'
   typeof attributes.ready; // 'string'

   return { type: 'div', props: attributes };
  }

The value of each XML node attribute is a string.
If we coerce each the type of each value, we would instead the following:

function convertPerson (attributes) {
   typeof attributes.name; // 'string'
   typeof attributes.age; // 'number'
   typeof attributes.ready; // 'boolean'

   return { type: 'div', props: attributes };
  }

for boolean attributes, we should consider HTML's approach

related: #16 (comment)

@pgoldrbx
Copy link
Contributor

pgoldrbx commented Dec 18, 2017

I was thinking we'd:

  1. test against 'undefined'
  2. call JSON.parse()

anything else? XML doesn't have implicit boolean attributes like HTML (or am i crazy?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants