code: function serializeObject(value: mixed): mixed {
    if (typeof value === 'object' && value !== null) {
      if (typeof value.valueOf === 'function') {
        const valueOfResult = value.valueOf();
        if (typeof valueOfResult !== 'object') {
          return valueOfResult;
        }
      }
      if (typeof value.toJSON === 'function') {
        // $FlowFixMe(>=0.90.0)
        return value.toJSON();
      }
    }
    return value;
  }
docs: Support serializing objects with custom valueOf() or toJSON() functions - a common way to represent a complex value which can be represented as a string (ex: MongoDB id objects).