Skip to content

Commit

Permalink
Merge pull request #32 from eotsevych/issue/30-fix-json-deserializati…
Browse files Browse the repository at this point in the history
…on-error

[Update] Flatten nested "target" arrays in Axe results
  • Loading branch information
sridharbandi authored Oct 10, 2024
2 parents a377c8a + 15507ce commit 717ebdd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/resources/js/axe.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ async function axeData(params) {
results.device = device();
results.browser = getBrowser();
results.date = getFormattedDate();

flattenTargetArrays(results.violations);
flattenTargetArrays(results.incomplete);
flattenTargetArrays(results.inapplicable);
return results;
}

Expand Down Expand Up @@ -100,4 +104,18 @@ function injectAxeScript(scriptURL) {
script.addEventListener('error', e => reject(e.error));
document.head.appendChild(script);
});
}

function flattenTargetArrays(resultsArray) {
if (Array.isArray(resultsArray)) {
resultsArray.forEach(result => {
if (result.nodes && Array.isArray(result.nodes)) {
result.nodes.forEach(node => {
if (node.target && Array.isArray(node.target)) {
node.target = node.target.flat();
}
});
}
});
}
}

0 comments on commit 717ebdd

Please sign in to comment.