lib/encoder.js
function value(val, buf, simple) {
  buf = buf || new Buffer(0);
  var type = typeof val;

  // coerce booleans to integers
  val = type === 'boolean' ? Number(val) : val;

  // treat floats as strings
  if(type === 'number' && parseInt(val) !== val) {
    val = '' + val;
  }

  // String instances are treated as simple strings
  if(val instanceof String) {
    simple = true;
    val = val.toString();
  }

  // re-evaluate type after coercion
  type = typeof val;

  if(val instanceof Buffer) {
    buf = _bst(buf, val);
  }else if(val === null) {
    buf = _nil(buf);
  }else if(Array.isArray(val)) {
    buf = _arr(buf, val);
  }else if(type === 'number'){
    buf = _int(buf, val);
  }else if(type === 'string') {
    buf = simple ? _str(buf, val) : _bst(buf, val);
  }else if(val instanceof Error) {
    buf = _err(buf, val);
  }else{
    assert(false, 'invalid encoder type: ' + type);
  }
  return buf;
}
function value(val, buf, simple) {
  buf = buf || new Buffer(0);
  var type = typeof val;

  // coerce booleans to integers
  val = type === 'boolean' ? Number(val) : val;

  // treat floats as strings
  if(type === 'number' && parseInt(val) !== val) {
    val = '' + val;
  }

  // String instances are treated as simple strings
  if(val instanceof String) {
    simple = true;
    val = val.toString();
  }

  // re-evaluate type after coercion
  type = typeof val;

  if(val instanceof Buffer) {
    buf = _bst(buf, val);
  }else if(val === null) {
    buf = _nil(buf);
  }else if(Array.isArray(val)) {
    buf = _arr(buf, val);
  }else if(type === 'number'){
    buf = _int(buf, val);
  }else if(type === 'string') {
    buf = simple ? _str(buf, val) : _bst(buf, val);
  }else if(val instanceof Error) {
    buf = _err(buf, val);
  }else{
    assert(false, 'invalid encoder type: ' + type);
  }
  return buf;
}
function value ( val , buf , simple ) { buf = buf || new Buffer ( 0 ) ; var type = typeof val ; // coerce booleans to integers val = type === 'boolean' ? Number ( val ) : val ; // treat floats as strings if ( type === 'number' && parseInt ( val ) !== val ) { val = '' + val ; } // String instances are treated as simple strings if ( val instanceof String ) { simple = true ; val = val . toString ( ) ; } // re-evaluate type after coercion type = typeof val ; if ( val instanceof Buffer ) { buf = _bst ( buf , val ) ; } else if ( val === null ) { buf = _nil ( buf ) ; } else if ( Array . isArray ( val ) ) { buf = _arr ( buf , val ) ; } else if ( type === 'number' ) { buf = _int ( buf , val ) ; } else if ( type === 'string' ) { buf = simple ? _str ( buf , val ) : _bst ( buf , val ) ; } else if ( val instanceof Error ) { buf = _err ( buf , val ) ; } else { assert ( false , 'invalid encoder type: ' + type ) ; } return buf ; }
Encode a single javascript value.

@param val The value to encode.
@param buf A buffer to append the encoded contents to (optional).
@param simple Force a string value to be treated as a simple string.

@return A buffer with the RESP encoded contents.
Encode a single javascript value .