index.js
function castBuffer (val) {
  if (Buffer.isBuffer(val)) {
    return val
  }

  val = toJSON(val)
  var args = assertArgs([val], {
    val: ['string', 'array', 'object', 'number', 'boolean']
  })
  val = args.val

  var str

  if (Array.isArray(val)) {
    val = val.map(toJSON)
    str = JSON.stringify(val)
  } else if (isObject(val)) {
    val = toJSON(val)
    str = JSON.stringify(val)
  } else { // val is a string, number, or boolean
    str = val + ''
  }

  return new Buffer(str)
}
function castBuffer (val) {
  if (Buffer.isBuffer(val)) {
    return val
  }

  val = toJSON(val)
  var args = assertArgs([val], {
    val: ['string', 'array', 'object', 'number', 'boolean']
  })
  val = args.val

  var str

  if (Array.isArray(val)) {
    val = val.map(toJSON)
    str = JSON.stringify(val)
  } else if (isObject(val)) {
    val = toJSON(val)
    str = JSON.stringify(val)
  } else { // val is a string, number, or boolean
    str = val + ''
  }

  return new Buffer(str)
}
function castBuffer ( val ) { if ( Buffer . isBuffer ( val ) ) { return val } val = toJSON ( val ) var args = assertArgs ( [ val ] , { val : [ 'string' , 'array' , 'object' , 'number' , 'boolean' ] } ) val = args . val var str if ( Array . isArray ( val ) ) { val = val . map ( toJSON ) str = JSON . stringify ( val ) } else if ( isObject ( val ) ) { val = toJSON ( val ) str = JSON . stringify ( val ) } else { // val is a string, number, or boolean str = val + '' } return new Buffer ( str ) }
cast value to buffer
@param  {Buffer|Object|Array|String|Boolean} val value to be casted
@return {Buffer}     value as a Buffer
cast value to buffer