@wildpeaks/snapshot-dom
Advanced tools
Comparing version 1.4.0 to 1.5.0
{ | ||
"name": "@wildpeaks/snapshot-dom", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Converts a DOM element to a JSON tree", | ||
"author": "Cecile Muller", | ||
"license": "MIT", | ||
"keywords": [ | ||
"wildpeaks", | ||
"assert", | ||
"dom" | ||
], | ||
"homepage": "https://github.com/wildpeaks/package-snapshot-dom#readme", | ||
"repository": "https://github.com/wildpeaks/package-snapshot-dom", | ||
"bugs": { | ||
"url": "https://github.com/wildpeaks/package-snapshot-dom/issues" | ||
}, | ||
"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", | ||
"files": [ | ||
"src/snapshot.js", | ||
"test/snapshot.tests.js" | ||
"src" | ||
], | ||
"scripts": { | ||
"test:lint": "eslint ./src/**/*.js", | ||
"test:specs": "mocha", | ||
"test": "npm run test:lint && npm run test:specs" | ||
"lint": "eslint ./src/**/*.js", | ||
"test": "mocha test/*.spec.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/wildpeaks/package-snapshot-dom.git" | ||
}, | ||
"keywords": [ | ||
"wildpeaks", | ||
"assert", | ||
"dom" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/wildpeaks/package-snapshot-dom/issues" | ||
}, | ||
"homepage": "https://github.com/wildpeaks/package-snapshot-dom#readme", | ||
"devDependencies": { | ||
"@wildpeaks/eslint-config-commonjs": "6.2.0", | ||
"eslint": "6.1.0", | ||
"jsdom": "15.1.1", | ||
"mocha": "6.2.0" | ||
"@wildpeaks/eslint-config-commonjs": "8.0.0", | ||
"eslint": "6.8.0", | ||
"jsdom": "15.2.1", | ||
"mocha": "6.2.2", | ||
"prettier": "1.19.1" | ||
} | ||
} |
# 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. | ||
@@ -4,0 +6,0 @@ |
@@ -1,4 +0,3 @@ | ||
'use strict'; | ||
"use strict"; | ||
/** | ||
@@ -10,14 +9,14 @@ * Convert a DOM element to a simpler JSON tree. | ||
*/ | ||
function toJSON(node, skipEmpty){ | ||
function toJSON(node, skipEmpty) { | ||
const serialized = {}; | ||
const isValid = (typeof node === 'object') && (node !== null); | ||
if (isValid){ | ||
const isValid = typeof node === "object" && node !== null; | ||
if (isValid) { | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType#Node_type_constants | ||
// serialized.nodeType = node.nodeType; | ||
if (node.tagName){ | ||
if (node.tagName) { | ||
serialized.tagName = node.tagName.toLowerCase(); | ||
} else if (node.nodeName){ | ||
} else if (node.nodeName) { | ||
serialized.nodeName = node.nodeName; | ||
} | ||
if (node.nodeValue){ | ||
if (node.nodeValue) { | ||
serialized.nodeValue = node.nodeValue; | ||
@@ -27,10 +26,10 @@ } | ||
const attrs = node.attributes; | ||
if (attrs){ | ||
if (attrs) { | ||
const l = attrs.length; | ||
if (l > 0){ | ||
if (l > 0) { | ||
const aggregated = {}; | ||
for (let i = 0; i < l; i++){ | ||
for (let i = 0; i < l; i++) { | ||
const attr = attrs[i]; | ||
const skip = skipEmpty && !attr.nodeValue; | ||
if (!skip){ | ||
if (!skip) { | ||
aggregated[attr.nodeName] = attr.nodeValue; | ||
@@ -44,7 +43,7 @@ } | ||
const {childNodes} = node; | ||
if (childNodes){ | ||
if (childNodes) { | ||
const l = childNodes.length; | ||
if (l > 0){ | ||
if (l > 0) { | ||
const aggregated = new Array(l); | ||
for (let i = 0; i < l; i++){ | ||
for (let i = 0; i < l; i++) { | ||
aggregated[i] = toJSON(childNodes[i], skipEmpty); | ||
@@ -59,4 +58,2 @@ } | ||
module.exports.toJSON = toJSON; | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
95
5090
5
4
51
1
1