<commit_before>'use strict'

var keys = require('../common/keys')
var methods = require('../common/methods')
var errors = require('../common/errors')
var castValue = require('../common/cast_value')
var castToNumber = require('../common/cast_to_number')
var promise = require('../common/promise')
var message = require('../common/message')

var HttpSerializer = require('./http_serializer')
var initializeContext = require('./http_initialize_context')
var encodeRoute = require('./http_encode_route')


module.exports = instantiateSerializer


function instantiateSerializer (instance, serializer, options) {
  var Promise = promise.Promise
  var CustomSerializer, mediaType

  if (typeof serializer !== 'function')
    throw new TypeError('The HTTP serializer must be a function.')

  if (options === void 0) options = {}

  CustomSerializer = HttpSerializer.prototype
    .isPrototypeOf(serializer.prototype) ?
      serializer : serializer(HttpSerializer)

  if (!HttpSerializer.prototype.isPrototypeOf(CustomSerializer.prototype))
    throw new TypeError('The serializer must inherit the HttpSerializer ' +
      'class.')

  mediaType = CustomSerializer.mediaType

  if (typeof mediaType !== 'string')
    throw new TypeError('A media type must be defined as a string for the ' +
      'HttpSerializer.')

  return new CustomSerializer({<commit_msg>add check for instance type<commit_after>'use strict'

var Fortune = require('../core')
var keys = require('../common/keys')
var methods = require('../common/methods')
var errors = require('../common/errors')
var castValue = require('../common/cast_value')
var castToNumber = require('../common/cast_to_number')
var promise = require('../common/promise')
var message = require('../common/message')

var HttpSerializer = require('./http_serializer')
var initializeContext = require('./http_initialize_context')
var encodeRoute = require('./http_encode_route')


module.exports = instantiateSerializer


function instantiateSerializer (instance, serializer, options) {
  var Promise = promise.Promise
  var CustomSerializer, mediaType

  if (!(instance instanceof Fortune))
    throw new TypeError('An instance of Fortune is required.')

  if (typeof serializer !== 'function')
    throw new TypeError('The HTTP serializer must be a function.')

  if (options === void 0) options = {}

  CustomSerializer = HttpSerializer.prototype
    .isPrototypeOf(serializer.prototype) ?
      serializer : serializer(HttpSerializer)

  if (!HttpSerializer.prototype.isPrototypeOf(CustomSerializer.prototype))
    throw new TypeError('The serializer must inherit the HttpSerializer ' +
      'class.')

  mediaType = CustomSerializer.mediaType

  if (typeof mediaType !== 'string')
    throw new TypeError('A media type must be defined as a string for the ' +
      'HttpSerializer.')

  return new CustomSerializer({
{'fraction_non_alphanumeric': 0.12119089316987741, 'fraction_numerical': 0.0007005253940455342, 'mean_word_length': 4.622047244094488, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '352428', 'n_tokens_mistral': 759, 'n_tokens_neox': 734, 'n_words': 222}