@feizheng/next-dom2json

1.0.1 • Public • Published

next-dom2json

Dom to json for next.

version license size download

installation

npm install -S @feizheng/next-dom2json

usage

import '@feizheng/next-dom2json';

const domElement = `
  <div class="list_item odd" data-value="v1" itemscope="" itemtype="http://schema.org/Movie">
    123
    <span>abc</span>
    <strong>def</strong>
  </div>
`;
const dom = new JSDOM(domElement);
const el = dom.window.document.querySelector('.list_item');
const json = nx.dom2json(el);

// results:
/*
{
  nodeName: 'div',
  nodeType: 1,
  attributes: {
    class: 'list_item odd',
    'data-value': 'v1',
    itemscope: '',
    itemtype: 'http://schema.org/Movie'
  },
  childNodes: [
    {
      nodeName: '#text',
      nodeType: 3,
      nodeValue: '\n        123\n        ',
      childNodes: []
    },
    {
      nodeName: 'span',
      nodeType: 1,
      attributes: {},
      childNodes: [
        {
          nodeName: '#text',
          nodeType: 3,
          nodeValue: 'abc',
          childNodes: []
        }
      ]
    },
    {
      nodeName: '#text',
      nodeType: 3,
      nodeValue: '\n        ',
      childNodes: []
    },
    {
      nodeName: 'strong',
      nodeType: 1,
      attributes: {},
      childNodes: [
        {
          nodeName: '#text',
          nodeType: 3,
          nodeValue: 'def',
          childNodes: []
        }
      ]
    },
    {
      nodeName: '#text',
      nodeType: 3,
      nodeValue: '\n      ',
      childNodes: []
    }
  ]
}
*/

resources

license

Code released under the MIT license.

Readme

Keywords

none

Package Sidebar

Install

npm i @feizheng/next-dom2json

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

6.96 kB

Total Files

5

Last publish

Collaborators

  • afeiship