Needlessly Provoking Marsupials
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

jsx-to-json

0.2.3 • Public • Published

jsx-to-json

将 JSX 代码转化为 JSON 对象, 例如

  <Layout>
    <Row style={{ padding: 10, backgroundColor: "#EFEFEF" }}>
      <BroccoliVote
        style={{ fontSize: "80%" }}
        options{[
          { name: "选项1", value: 1 },
          { name: "选项2", value: 2 },
          { name: "选项3", value: 3 },
        ]}
      />
    </Row>
    <Row>
      <Share text="一起来参与投票吧!亮出你的态度"/>
    </Row>
  </Layout>

转化为

{
  "type": "Layout",
  "children": [
    {
      "type": "Row",
      "props": {
        "style": {
          "padding": 10,
          "backgroundColor": "#FFF"
        }
      },
      "children": [
        {
          "type": "h1",
          "text": "标题"
        },
        {
          "type": "BroccoliVote",
          "props": {
            "style": {
              "fontSize": "80%"
            },
            "options": [
              {
                "name": "选项1",
                "value": 1
              },
              {
                "name": "选项2",
                "value": 2
              },
              {
                "name": "选项3",
                "value": 3
              }
            ]
          }
        }
      ]
    },
    {
      "type": "Row",
      "children": [
        {
          "type": "Share",
          "props": {
            "text": "一起来参与投票吧!亮出你的态度"
          }
        }
      ]
    }
  ]
}

使用

import { jsxToJson } from 'jsx-to-json';
 
const jsonObject = jsxToJson(code);

install

npm i jsx-to-json

Downloadsweekly downloads

30

version

0.2.3

license

ISC

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability