src/encode.js

Method encode

Encodes arg as JSON if applicable

Parameters:

  • arg can be of any type.
    (Object to encode)

Returns a Mixed
(Original Object or JSON string)

TurtleIO.prototype.encode = function ( arg ) {

Do not want to coerce this Object to a String!

if ( arg instanceof Buffer || typeof arg.pipe === "function" ) { return arg; }

Converting to JSON

else if ( arg instanceof Array || arg instanceof Object ) { return $.encode( arg ); }

Nothing to do, leave it as it is

else { return arg; } };