Skip to content

Commit

Permalink
Made human id 4 characters shorter while maintaining same data amount
Browse files Browse the repository at this point in the history
  • Loading branch information
martinheidegger committed Jan 23, 2020
1 parent 0b83c8b commit bea61a6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/util/humanModelId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ import { Buffer } from 'buffer'

export function humanModelId (modelId: string): string {
const idBuffer = Buffer.from(modelId, 'utf8')
return `${idBuffer.readUInt16BE(0).toString(16)}-${idBuffer.readUInt16BE(1).toString(16)}-${idBuffer.readUInt16BE(2).toString(16)}-${idBuffer.readUInt16BE(3).toString(16)}`.toUpperCase()
return `${idBuffer.readUInt16BE(0).toString(32)}${idBuffer.readUInt16BE(1).toString(32)}${idBuffer.readUInt16BE(2).toString(32)}${idBuffer.readUInt16BE(3).toString(32)}`
.toUpperCase()
.split(/(.{4})/g)
.filter(Boolean)
.join('-')
}

0 comments on commit bea61a6

Please sign in to comment.