'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _roundTo = require('round-to');

var _roundTo2 = _interopRequireDefault(_roundTo);

var _utm = require('utm');

var _sexagesimal = require('@mapbox/sexagesimal');

var _sexagesimal2 = _interopRequireDefault(_sexagesimal);

var _constants = require('../constants');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function formatLocation(coords, format) {
  if (!(Array.isArray(coords) && coords.length === 2)) return coords;
  switch (format) {
    case _constants.FORMATS_DEC_DEG:
      return coords.map(function (coord) {
        return (0, _roundTo2.default)(coord, 5);
      }).join(', ');
    case _constants.FORMATS_DEG_MIN_SEC:
      return _sexagesimal2.default.formatPair({ lon: coords[0], lat: coords[1] }).replace(/'/g, '’').replace(/"/g, '”');
    case _constants.FORMATS_UTM:
      var utm = (0, _utm.fromLatLon)(coords[1], coords[0]);
      return 'X ' + (0, _roundTo2.default)(utm.easting, 1) + ', Y ' + (0, _roundTo2.default)(utm.northing, 1) + ' \u2014 UTM ' + utm.zoneNum + utm.zoneLetter;
  }
}

exports.default = formatLocation;
//# sourceMappingURL=formatLocation.js.map