1.0.1 • Published 4 years ago

@feizheng/next-dom2json v1.0.1

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

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.

1.0.1

4 years ago

1.0.0

4 years ago