"use strict";

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

function arr2Dic() {
  var arr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var field = arguments.length > 1 ? arguments[1] : undefined;
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  var _options$alwaysArray = options.alwaysArray,
      alwaysArray = _options$alwaysArray === void 0 ? false : _options$alwaysArray;
  var dic = {};
  arr.forEach(function (vo) {
    if (dic[vo[field]]) {
      if (!Array.isArray(dic[vo[field]])) dic[vo[field]] = [dic[vo[field]]];
      dic[vo[field]].push(vo);
      return;
    }

    dic[vo[field]] = alwaysArray ? [vo] : vo;
  }); // @ts-ignore

  return dic;
}