Skip to content

Commit b8339b0

Browse files
committed
Proper normalize function
1 parent 174031c commit b8339b0

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

main.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,23 @@ function normalizeTxPwr(adifdata) {
320320
});
321321
}
322322

323+
function normalizeKIndex(adifdata) {
324+
return adifdata.replace(/<K_INDEX:(\d+)>([^<]+)/gi, (match, length, value) => {
325+
const numValue = parseFloat(value.trim());
326+
if (isNaN(numValue)) return ''; // Remove if not a number
327+
328+
// Round to nearest integer and clamp to 0-9 range
329+
let kIndex = Math.round(numValue);
330+
if (kIndex < 0) kIndex = 0;
331+
if (kIndex > 9) kIndex = 9;
332+
333+
return `<K_INDEX:${kIndex.toString().length}>${kIndex}`;
334+
});
335+
}
336+
323337
function manipulateAdifData(adifdata) {
324338
adifdata = normalizeTxPwr(adifdata);
325-
326-
// Remove K_INDEX fields - fix for Log4OM
327-
adifdata = adifdata.replace(/<K_INDEX:\d+>[^<]+/gi, '');
339+
adifdata = normalizeKIndex(adifdata);
328340
// add more manipulation if necessary here
329341
// ...
330342
return adifdata;

0 commit comments

Comments
 (0)