lib/document.js
/**
 * Serialize an object to be persisted to a one-line string
 * For serialization/deserialization, we use the native JSON parser and not eval or Function
 * That gives us less freedom but data entered in the database may come from users
 * so eval and the like are not safe
 * Accepted primitive types: Number, String, Boolean, Date, null
 * Accepted secondary types: Objects, Arrays
 */
Serialize an object to be persisted to a one-line string
For serialization/deserialization, we use the native JSON parser and not eval or Function
That gives us less freedom but data entered in the database may come from users
so eval and the like are not safe
Accepted primitive types: Number, String, Boolean, Date, null
Accepted secondary types: Objects, Arrays
Serialize an object to be persisted to a one - line string For serialization / deserialization we use the native JSON parser and not eval or Function That gives us less freedom but data entered in the database may come from users so eval and the like are not safe Accepted primitive types : Number String Boolean Date null Accepted secondary types : Objects Arrays
function serialize (obj) {
  var res;
  res = JSON.stringify(obj, function (k, v) {
    checkKey(k, v);
    if (v === undefined) { return undefined; }
    if (v === null) { return null; }
    if (typeof this[k].getTime === 'function') { return { $$date: this[k].getTime() }; }
    if (typeof this[k].test === 'function') { return { $$regex: this[k].toString() }; }
    return v;
  });
  return res;
}
function serialize ( obj ) { var res ; res = JSON . stringify ( obj , function ( k , v ) { checkKey ( k , v ) ; if ( v === undefined ) { return undefined ; } if ( v === null ) { return null ; } if ( typeof this [ k ] . getTime === 'function' ) { return { $$date : this [ k ] . getTime ( ) } ; } if ( typeof this [ k ] . test === 'function' ) { return { $$regex : this [ k ] . toString ( ) } ; } return v ; } ) ; return res ; }
Serialize an object to be persisted to a one-line string
 For serialization/deserialization, we use the native JSON parser and not eval or Function
 That gives us less freedom but data entered in the database may come from users
 so eval and the like are not safe
 Accepted primitive types: Number, String, Boolean, Date, null
 Accepted secondary types: Objects, Arrays
Serialize an object to be persisted to a one - line string For serialization / deserialization we use the native JSON parser and not eval or Function That gives us less freedom but data entered in the database may come from users so eval and the like are not safe Accepted primitive types : Number String Boolean Date null Accepted secondary types : Objects Arrays
// Hackish way of checking if object is Date (this way it works between execution contexts in node-webkit). // We can't use value directly because for dates it is already string in this function (date.toJSON was already called), so we use this // same shit for RegExp