@wildpeaks/snapshot-dom
Advanced tools
Comparing version 1.6.0 to 2.0.0-rc1
/* eslint-env browser */ | ||
"use strict"; | ||
(function() { | ||
function snapshotToJson(node, skipEmpty) { | ||
function snapshotToJson(node, options = {}) { | ||
const serialized = {}; | ||
@@ -24,3 +24,3 @@ const isValid = typeof node === "object" && node !== null; | ||
const attr = attrs[i]; | ||
const skip = skipEmpty && !attr.nodeValue; | ||
const skip = options.skipEmptyValue && !attr.nodeValue; | ||
if (!skip) { | ||
@@ -40,3 +40,3 @@ aggregated[attr.nodeName] = attr.nodeValue; | ||
for (let i = 0; i < l; i++) { | ||
aggregated[i] = snapshotToJson(childNodes[i], skipEmpty); | ||
aggregated[i] = snapshotToJson(childNodes[i], options); | ||
} | ||
@@ -43,0 +43,0 @@ serialized.childNodes = aggregated; |
{ | ||
"name": "@wildpeaks/snapshot-dom", | ||
"version": "1.6.0", | ||
"version": "2.0.0-rc1", | ||
"description": "Converts a DOM element to a JSON tree", | ||
@@ -42,10 +42,10 @@ "author": "Cecile Muller", | ||
"devDependencies": { | ||
"@wildpeaks/eslint-config-commonjs": "8.0.0", | ||
"@wildpeaks/eslint-config-commonjs": "8.1.0", | ||
"eslint": "6.8.0", | ||
"express": "4.17.1", | ||
"jsdom": "15.2.1", | ||
"mocha": "6.2.2", | ||
"jsdom": "16.1.0", | ||
"mocha": "7.0.1", | ||
"prettier": "1.19.1", | ||
"puppeteer": "2.0.0" | ||
"puppeteer": "2.1.1" | ||
} | ||
} |
@@ -60,3 +60,3 @@ # Snapshot | ||
assert.deepStrictEqual( | ||
snapshot.toJSON(document.body, false), | ||
snapshot.toJSON(document.body, {skipEmptyValue: false}), | ||
{ | ||
@@ -79,3 +79,3 @@ tagName: 'body', | ||
assert.deepStrictEqual( | ||
snapshot.toJSON(document.body, true), | ||
snapshot.toJSON(document.body, {skipEmptyValue: true}), | ||
{ | ||
@@ -95,3 +95,3 @@ tagName: 'body', | ||
Note that strings containing only whitespace are not empty. | ||
Note that strings containing only whitespace characters are not empty values. | ||
"use strict"; | ||
/** | ||
* @typedef {Object} Options | ||
* @property {Boolean} skipEmptyValue - Skips node values that evaluate to false (undefined and zero-length strings) | ||
*/ | ||
/** | ||
* Convert a DOM element to a simpler JSON tree. | ||
* @param {Node} node | ||
* @param {Boolean} skipEmpty Skips node values that evaluate to false (undefined and empty strings) | ||
* @param {Options} options | ||
* @return {Object} | ||
*/ | ||
function toJSON(node, skipEmpty) { | ||
function toJSON(node, options = {}) { | ||
const serialized = {}; | ||
@@ -31,3 +36,3 @@ const isValid = typeof node === "object" && node !== null; | ||
const attr = attrs[i]; | ||
const skip = skipEmpty && !attr.nodeValue; | ||
const skip = options.skipEmptyValue && !attr.nodeValue; | ||
if (!skip) { | ||
@@ -47,3 +52,3 @@ aggregated[attr.nodeName] = attr.nodeValue; | ||
for (let i = 0; i < l; i++) { | ||
aggregated[i] = toJSON(childNodes[i], skipEmpty); | ||
aggregated[i] = toJSON(childNodes[i], options); | ||
} | ||
@@ -50,0 +55,0 @@ serialized.childNodes = aggregated; |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6493
101
1