Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

skava / exotic   js

Repository URL to install this package:

Version: 2.0.8 

/ src / types / primitive / number / binary / fromBinaryToPrettyBinary.ts

/**
 * formats binary with spaces @ every 10 spaces
 */
function fromBinaryToPrettyBinary(binary: number | string): string {
  let index = -1
  const msgs = ['', '']

  return (binary as string)
    .split('')
    .map(char => {
      index += 1
      if (index % 8 === 0) {
        msgs[0] += '10'
        msgs[1] += '| '
        return ' | ' + char
      } else if (index % 2 === 0) {
        msgs[0] += ' '
        msgs[1] += ' '
        return ',' + char
      } else {
        msgs[0] += ' '
        msgs[1] += ' '
        return '' + char
      }
    })
    .join('')
    .replace(' | ', '')
}

export { fromBinaryToPrettyBinary }
export default fromBinaryToPrettyBinary