param length param begin export const range = ( length , begin = 0 ) => Array . from ( { length } , ( _ , index ) => begin + index ) ; /**
 * Split a string into an array of `chunkLength` strings. The final string may have a length between 1 and `chunkLength`.
 *
 * E.g.: `splitEvery('abcde', 2)` → `['ab', 'cd', 'e']`
 */ export const splitEvery = ( input , chunkLength ) => range ( Math . ceil ( input . length / chunkLength ) ) . map ( ( index ) => index * chunkLength ) . map ( ( begin ) => input . slice ( begin , begin + chunkLength ) ) ; const hexByteWidth = 2 ; const hexadecimal = 16 ; param validHex export const hexToBin = ( validHex ) => Uint8Array . from ( splitEvery ( validHex , hexByteWidth ) . map ( ( byte ) => parseInt ( byte , hexadecimal ) ) ) ; param maybeHex export const isHex = ( maybeHex ) => maybeHex . length % hexByteWidth === 0 && ! /[^a-fA-F0-9]/u . test ( maybeHex ) ; param bytes export const binToHex = ( bytes ) => bytes . reduce ( ( str , byte ) => str + byte . toString ( hexadecimal ) . padStart ( hexByteWidth , '0' ) , '' ) ; param validHex export const swapEndianness = ( validHex ) => binToHex ( hexToBin ( validHex ) . reverse ( ) ) ; param array export const flattenBinArray = ( array ) => { const totalLength = array . reduce ( ( total , bin ) => total + bin . length , 0 ) ; const flattened = new Uint8Array ( totalLength ) ; array . reduce ( ( index , bin ) => { flattened . set ( bin , index ) ; return index + bin . length ; } , 0 ) ; return flattened ; } ;