arrbuf2hex
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

arrbuf2hex

fast custom array buffer to hexadecimal string function for when you need hexadecimal numbers out of a buffer and they don't always align.

also practiacally all the functions in this are bitwise so uh it's nigh instant.

use:

const { buf2hex } = require('arrbuf2hex')
buf2hex(new ArrayBuffer(8), 0, 3, true)
// 000
buf2hex(Uint8Array.of(0xff, 0xf0, 0x0f), 1, 3)
// ff0
buf2hex(Uint8Array.of(0xff, 0xf0, 0x0f), 0, 5, true)
// fff00

or

import { buf2hex } from 'arrbuf2hex'
buf2hex(new ArrayBuffer(8), 0, 3, true)
// 000

in the browser:

import { buf2hex } from '/node_modules/arrbuf2hex/arrbuf2hex.es'
crypto.subtle.digest('SHA-1', arrbuf).then(buf2hex).then(hash => {
  // print hash
})
(async () => {
  const hash = buf2hex(await crypto.subtle.digest('SHA-1', new ArrayBuffer(0)))
  console.assert("da39a3ee5e6b4b0d3255bfef95601890afd80709" === hash, `SHA-1 invalid, zero returns ${hash} instead of da39a3ee5e6b4b0d3255bfef95601890afd80709`)
})

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.2.1
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.2.1
    1
  • 1.2.0
    0
  • 1.1.0
    0

Package Sidebar

Install

npm i arrbuf2hex

Weekly Downloads

1

Version

1.2.1

License

WTFPL

Unpacked Size

33.9 kB

Total Files

19

Last publish

Collaborators

  • zeen3