@tak-ps/node-cot
Version:
Lightweight JavaScript library for parsing and manipulating TAK messages
38 lines • 1.47 kB
JavaScript
export function visitElementAttributes(input, visitor, path = []) {
if (Array.isArray(input)) {
for (const [index, value] of input.entries()) {
visitElementAttributes(value, visitor, [...path, String(index)]);
}
return;
}
if (!input || typeof input !== 'object') {
return;
}
const record = input;
for (const [key, value] of Object.entries(record)) {
if (key === '_attributes' && value && typeof value === 'object' && !Array.isArray(value)) {
const attributes = value;
for (const [attributeKey, attributeValue] of Object.entries(attributes)) {
visitor(attributeKey, attributeValue, attributes, [...path, key]);
visitElementAttributes(attributes[attributeKey], visitor, [...path, key, attributeKey]);
}
continue;
}
visitElementAttributes(value, visitor, [...path, key]);
}
}
export function normalizeBooleanAttributeValues(input) {
visitElementAttributes(input, (attributeKey, attributeValue, attributes) => {
if (typeof attributeValue !== 'string') {
return;
}
const normalized = attributeValue.toLowerCase();
if (normalized === 'true') {
attributes[attributeKey] = true;
}
else if (normalized === 'false') {
attributes[attributeKey] = false;
}
});
}
//# sourceMappingURL=parser-normalize.js.map