Skip to content

Converts simplified JSX code into a JSON representation, which can be used by React.createElement

License

Notifications You must be signed in to change notification settings

ClearTax/simplified-jsx-to-json

 
 

Repository files navigation

simplified-jsx-to-json

Build Status npm version npm downloads

Converts simplified JSX code into a JSON representation, which can be used by React.createElement

Install

$ npm install simplified-jsx-to-json

Usage

const jsxToJson = require('simplified-jsx-to-json');

jsxToJson('<Test myProp={true}>My Child</Test>');
//=> '[ [ 'Test', { myProp: true }, "My Child" ] ]'

Features

  • <Test />: Self-closing JSX tags
  • <Test myProp="string">: String props
  • <Test myProp={`string`}>: Template props
  • <Test myProp>: True props
  • <Test myProp={false}>: Boolean props
  • <Test myProp={34}>: Number props
  • <Test myProp={3 + 3 + 3}>: Props with arithmetic, comparison or bitwise operators
  • <Test myProp={['Test', true, 34]}>: Arrays (with strings, numbers or booleans)
  • <Test myProp={{ test: 34 }}>: Objects with string keys and string, number or boolean value
  • <>Test</>: Fragments
  • HTML/SVG DOM attributes are converted to correct React equivalent (class -> className)

License

MIT © Dennis Morhardt

About

Converts simplified JSX code into a JSON representation, which can be used by React.createElement

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • JavaScript 99.4%
  • TypeScript 0.6%