From 8417de5756ab921863e7a7b8e4f3ca166e2e8ac7 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 29 Nov 2021 09:35:17 +0100 Subject: [PATCH] Extract checks with if-statements --- src/streamHandler/PacketStreamFactory.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/streamHandler/PacketStreamFactory.js b/src/streamHandler/PacketStreamFactory.js index 8980f4b..2a7175d 100644 --- a/src/streamHandler/PacketStreamFactory.js +++ b/src/streamHandler/PacketStreamFactory.js @@ -73,9 +73,14 @@ class PacketStreamFactory extends Transform{ 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]: - data.match(/(SA|TA|DA|RA|BSSID):.{17}\s*$/i)? PacketType.NoData: - PacketType.Unknown; + if(packetTypeStr) + packet.packetType = PACKET_TYPE_MAP[packetTypeStr]; + else if(data.match(/(SA|TA|DA|RA|BSSID):.{17}\s*$/i)){ + packet.packetType = PacketType.NoData + } + else { + packet.packetType = PacketType.Unknown; + } packet.srcMac = data.match(/(?<=(^|\s)(SA|TA):).{17}(?=$|\s)/i)?.[0] ?? null;