1
0
Fork 0
mirror of https://github.com/datashard/snapshot.git synced 2025-05-12 02:47:20 +00:00
snapshot/src/utils/serializers/deleteTransientIdsFromJson.js
2023-02-20 19:17:38 +01:00

16 lines
491 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;
};