@wildpeaks/snapshot-dom
Version:
Converts a DOM element to a JSON tree
1 lines • 485 B
JavaScript
;window.snapshotToJSON=function e(t){const o={};if("object"==typeof t&&null!==t){t.tagName?o.tagName=t.tagName.toLowerCase():t.nodeName&&(o.nodeName=t.nodeName),t.nodeValue&&(o.nodeValue=t.nodeValue);const n=t.attributes;if(n){const e=n.length;if(e>0){const t={};for(let o=0;o<e;o++){const e=n[o];t[e.nodeName]=e.nodeValue}o.attributes=t}}const{childNodes:a}=t;if(a){const t=a.length;if(t>0){const n=new Array(t);for(let o=0;o<t;o++)n[o]=e(a[o]);o.childNodes=n}}}return o};