From f5941f0f156548d0d775fcdbcb859e739c5c4629 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Sun, 19 Nov 2023 12:29:43 +0100 Subject: [PATCH] refactor: simplify toCode function --- lib/helpers.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/helpers.ts b/lib/helpers.ts index 94fc0fb2..a6a12fda 100644 --- a/lib/helpers.ts +++ b/lib/helpers.ts @@ -67,19 +67,10 @@ export function toCode (code: string | number): string { return code } - const first = Math.floor(code / 100) - const second = code - first * 100 - let result = '' + const codeClass = Math.floor(code / 100) + const codeDetail = String(code - codeClass * 100).padStart(2, '0') - result += String(first) + '.' - - if (second < 10) { - result += '0' - } - - result += String(second) - - return result + return `${codeClass}.${codeDetail}` } export function packetToMessage (dest: any, packet: CoapPacket): void {