'use strict';

var utils = require('../utils.js');
var toFormData = require('./toFormData.js');
var index = require('../platform/index.js');

function toURLEncodedForm(data, options) {
  return toFormData(data, new index.classes.URLSearchParams(), Object.assign({
    visitor: function(value, key, path, helpers) {
      if (index.isNode && utils.isBuffer(value)) {
        this.append(key, value.toString('base64'));
        return false;
      }

      return helpers.defaultVisitor.apply(this, arguments);
    }
  }, options));
}

module.exports = toURLEncodedForm;
