From 54eadf3bc360e7b05909116223ab75c0bdb70975 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 29 Nov 2021 09:24:18 +0100 Subject: [PATCH] Fixed Regex codesmells --- src/streamHandler/PacketStreamFactory.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/streamHandler/PacketStreamFactory.js b/src/streamHandler/PacketStreamFactory.js index ea1f5cb..8980f4b 100644 --- a/src/streamHandler/PacketStreamFactory.js +++ b/src/streamHandler/PacketStreamFactory.js @@ -65,12 +65,12 @@ class PacketStreamFactory extends Transform{ ?.forEach(match => packet.flags[FLAG_TYPE_MAP[match]] = true) // Set them to true in flags ); - packet.dataRate = Number(data.match(/(?<=^|\s)[0-9]+(\.[0-9]+)?(?=\sMb\/?s($|\s))/i)?.[0]) || null; - packet.frequency = Number(data.match(/(?<=^|\s)[0-9]{4}(?=\sMHz($|\s))/i)?.[0]) || null; + packet.dataRate = Number(data.match(/(?<=^|\s)\d+(\.\d+)?(?=\sMb\/?s($|\s))/i)?.[0]) || null; + packet.frequency = Number(data.match(/(?<=^|\s)\d{4}(?=\sMHz($|\s))/i)?.[0]) || null; - packet.durationMicros = Number(data.match(/(?<=^|\s)[0-9]{1,4}(?=us($|\s))/i)?.[0]) || null; + packet.durationMicros = Number(data.match(/(?<=^|\s)\d{1,4}(?=us($|\s))/i)?.[0]) || null; - packet.signal = Number(data.match(/(?<=^|\s)-[0-9]{2,3}(?=dBm\sSignal($|\s))/i)?.[0]) || null; + packet.signal = Number(data.match(/(?<=^|\s)-\d{2,3}(?=dBm\sSignal($|\s))/i)?.[0]) || null; let packetTypeStr = data.match(new RegExp('(?<=^|\\s)('+ PACKET_TYPES_REGEX +')(?=$|\\s)', 'i'))?.[0]; packet.packetType = packetTypeStr? PACKET_TYPE_MAP[packetTypeStr]: