text: "use strict";
  
  var QR = require('./qr-base.js').QR;
  var png = require('./png.js');
  var vector = require('./vector.js');
  var fs = require('./fs.js');
  
  var BITMAP_OPTIONS = {
      parse_url: false,
      ec_level: 'M',
      size: 5,
      margin: 4,
      customize: null
  };
  
  var VECTOR_OPTIONS = {
      parse_url: false,
      ec_level: 'M',
      margin: 1,
      size: 0
  };
  
  function get_options(options, force_type) {
      if (typeof options === 'string') {
          options = { 'ec_level': options }
      } else {
          options = options || {};
      }
      var _options = {
          type: String(force_type || options.type || 'png').toLowerCase()
      };
  
      var defaults = _options.type == 'png' ? BITMAP_OPTIONS : VECTOR_OPTIONS;
  
      for (var k in defaults) {
          _options[k] = k in options ? options[k] : defaults[k];
      }
  
      return _options;
  }
  
  function qr_image(text, options) {
      options = get_options(options);
  
      var matrix = QR(text, options.ec_level, options.parse_url);
      var stream = [];
  
      switch (options.type) {
      case 'svg':
      case 'pdf':
      case 'eps':
          vector[options.type](matrix, stream, options.margin, options.size);
          break;
      case 'svgpath':
          var obj = vector.svg_object(matrix, options.margin, options.size);
          stream.push(obj.path);
          stream.push(null);
          break;
      case 'png':
      default:
          var bitmap = png.bitmap(matrix, options.size, options.margin);
          if (options.customize) {
              options.customize(bitmap);
          }
          png.png(bitmap, stream);
      }
      return (''+stream.toString()).replace(/,/g,' ');
  }
  
  function qr_file(text, file, options) {
      fs.writeFileSync(file,qr_image(text, options));
  }
  
  function svg_object(text, options) {
      options = get_options(options, 'svg');
  
      var matrix = QR(text, options.ec_level);
      return vector.svg_object(matrix, options.margin);
  }
  
  module.exports = {
      matrix: QR,
      image: qr_image,
      file: qr_file,
      svgObject: svg_object
  };
  