UNPKG

@signalk/nmea0183-signalk

Version:

A node.js/javascript parser for NMEA0183 sentences. Sentences are parsed to Signal K format.

40 lines 1.26 kB
"use strict"; /** * transformSource.ts * * Checks if the "source" key in each update is an object; creates the object * when it's a string (or absent). Returns the passed-in `data` unchanged if * it's not a delta object. */ Object.defineProperty(exports, "__esModule", { value: true }); function transformSource(data, sentence, talker) { if (typeof data !== 'object' || data === null) { return data; } const delta = data; if (!Array.isArray(delta.updates)) { return data; } delta.updates = delta.updates.map((update) => { if (typeof update.source === 'object' && update.source !== null) { return update; } const _source = update.source || ''; const parts = _source.split(':'); const tagTalker = parts[0]; const tagSentence = parts[1]; let effectiveTalker = talker; if (effectiveTalker === 'nmea0183') { effectiveTalker = 'SK'; } update.source = { sentence: tagSentence || sentence, talker: tagTalker || effectiveTalker, type: 'NMEA0183' }; return update; }); return data; } exports.default = transformSource; //# sourceMappingURL=transformSource.js.map