import { splitEvery } from './hex' ; const binaryByteWidth = 8 ; const binary = 2 ; param validHex export const binStringToBin = ( binaryDigits ) => Uint8Array . from ( splitEvery ( binaryDigits , binaryByteWidth ) . map ( ( byteString ) => parseInt ( byteString , binary ) ) ) ; param bytes export const binToBinString = ( bytes ) => bytes . reduce ( ( str , byte ) => str + byte . toString ( binary ) . padStart ( binaryByteWidth , '0' ) , '' ) ; param maybeBinString export const isBinString = ( maybeBinString ) => maybeBinString . length % binaryByteWidth === 0 && ! /[^01]/u . test ( maybeBinString ) ;