Skip to content

Commit

Permalink
Merge pull request #372 from coapjs/simplify-tocode
Browse files Browse the repository at this point in the history
refactor: simplify toCode function
  • Loading branch information
JKRhb authored Jun 28, 2024
2 parents 2f37378 + 81ca68f commit 39c8527
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 39c8527

Please sign in to comment.