Socket
Socket
Sign inDemoInstall

@wildpeaks/snapshot-dom

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wildpeaks/snapshot-dom - npm Package Compare versions

Comparing version 2.0.0-rc1 to 2.0.0-rc2

lib/index.js

49

lib/browser.js

@@ -1,48 +0,1 @@

/* eslint-env browser */
"use strict";
(function() {
function snapshotToJson(node, options = {}) {
const serialized = {};
const isValid = typeof node === "object" && node !== null;
if (isValid) {
if (node.tagName) {
serialized.tagName = node.tagName.toLowerCase();
} else if (node.nodeName) {
serialized.nodeName = node.nodeName;
}
if (node.nodeValue) {
serialized.nodeValue = node.nodeValue;
}
const attrs = node.attributes;
if (attrs) {
const l = attrs.length;
if (l > 0) {
const aggregated = {};
for (let i = 0; i < l; i++) {
const attr = attrs[i];
const skip = options.skipEmptyValue && !attr.nodeValue;
if (!skip) {
aggregated[attr.nodeName] = attr.nodeValue;
}
}
serialized.attributes = aggregated;
}
}
const {childNodes} = node;
if (childNodes) {
const l = childNodes.length;
if (l > 0) {
const aggregated = new Array(l);
for (let i = 0; i < l; i++) {
aggregated[i] = snapshotToJson(childNodes[i], options);
}
serialized.childNodes = aggregated;
}
}
}
return serialized;
}
window.snapshotToJson = snapshotToJson;
})();
"use strict";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};
{
"name": "@wildpeaks/snapshot-dom",
"version": "2.0.0-rc1",
"version": "2.0.0-rc2",
"description": "Converts a DOM element to a JSON tree",

@@ -12,3 +12,3 @@ "author": "Cecile Muller",

],
"homepage": "https://github.com/wildpeaks/package-snapshot-dom#readme",
"homepage": "https://github.com/wildpeaks/package-snapshot-dom/tree/master/packages/snapshot-dom#readme",
"repository": "https://github.com/wildpeaks/package-snapshot-dom",

@@ -18,35 +18,9 @@ "bugs": {

},
"eslintConfig": {
"extends": "@wildpeaks/commonjs"
},
"prettier": {
"printWidth": 120,
"tabWidth": 4,
"useTabs": true,
"bracketSpacing": false
},
"greenkeeper": {
"commitMessages": {
"dependencyUpdate": "feat: update ${dependency}",
"devDependencyUpdate": "chore: update ${dependency}"
}
},
"main": "src/snapshot.js",
"main": "lib/index.js",
"browser": "lib/browser.js",
"files": [
"src",
"lib"
],
"scripts": {
"lint": "eslint ./src/**/*.js",
"test": "mocha test/*.spec.js"
},
"devDependencies": {
"@wildpeaks/eslint-config-commonjs": "8.1.0",
"eslint": "6.8.0",
"express": "4.17.1",
"jsdom": "16.1.0",
"mocha": "7.0.1",
"prettier": "1.19.1",
"puppeteer": "2.1.1"
}
"lib",
"removeEmptyAttributes",
"sortAttributes"
]
}
# Snapshot
[![Greenkeeper badge](https://badges.greenkeeper.io/wildpeaks/package-snapshot-dom.svg)](https://greenkeeper.io/)
Converts an HTMLElement to a JSON tree, useful for automated DOM tests.

@@ -48,48 +46,1 @@

````
---
## Skip empty values
It can optionally exclude empty values using the second parameter (default: `false`).
````js
document.body.innerHTML = '<img param1 param2="" param3="hello" />;
// Without skipping
assert.deepStrictEqual(
snapshot.toJSON(document.body, {skipEmptyValue: false}),
{
tagName: 'body',
childNodes: [
{
tagName: 'img',
attributes: {
param1: '',
param2: '',
param3: 'hello'
}
}
]
}
);
// With skipping
assert.deepStrictEqual(
snapshot.toJSON(document.body, {skipEmptyValue: true}),
{
tagName: 'body',
childNodes: [
{
tagName: 'img',
attributes: {
param3: 'hello'
}
}
]
}
);
````
Note that strings containing only whitespace characters are not empty values.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc