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

    93

    Version

    0.2.3

    License

    ISC

    Last publish

    Collaborators

    • ggd543
    • zhangmhao