1
0
Fork 0
mirror of https://github.com/datashard/snapshot.git synced 2025-05-20 05:57:21 +00:00
snapshot/src/utils/serializers/deleteTransientIdsFromJson.js
2022-09-09 14:50:23 +02:00

16 lines
475 B
JavaScript

// remove React and Angular ids, which are transient
module.exports = function deleteTransientIdsFromJson(json) {
if (json.attributes) {
delete json.attributes["data-reactid"];
Object.keys(json.attributes)
.filter((key) => key.startsWith("_ng"))
.forEach((attr) => delete json.attributes[attr]);
delete json.attributes[""];
}
if (Array.isArray(json.childNodes)) {
json.childNodes.forEach(deleteTransientIdsFromJson);
}
return json;
};