@xylabs/hex
Version:
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
14 lines (12 loc) • 483 B
text/typescript
import type { Hex, HexConfig } from '../model.ts'
import { hexFromHexString } from './fromHexString.ts'
/** Convert an ArrayBuffer to a hex string */
export const hexFromArrayBuffer = (
/** The buffer to be converted */
buffer: ArrayBufferLike,
/** Configuration of output format and validation */
config?: HexConfig,
): Hex => {
const unPadded = [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')
return hexFromHexString(unPadded, config)
}