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 / toBinary.ts

import isString from '../../string/isStringPrimitive'
import isNumber from '../../number/check/isNumberPrimitive'
import toNumber from '../../number/cast/toNumber'
import fromStringToUint31 from '../../number/cast/fromStringToUint31'
import fromBinaryToPrettyBinary from './fromBinaryToPrettyBinary'
import fromNumberToBase64Binary from './fromNumberToBase64Binary'

/**
 * @todo could also use toByteSize for non string|number
 *
 * @description convert anything to binary
 */
function toBinary(x: number | string | any): number | string | any {
  if (isString(x)) {
    const nummy = fromStringToUint31(x)
    return fromNumberToBase64Binary(nummy)
  } else if (isNumber(x)) {
    return fromNumberToBase64Binary(x)
  } else {
    const nummy = toNumber(x)
    return fromNumberToBase64Binary(nummy)
  }
}

export { toBinary }
export default toBinary