"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var checkKey = function checkKey(data, key) {
  var optionalKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

  if (optionalKeys[key]) {
    return {
      valid: 0,
      total: 0
    };
  }

  var valid = data.filter(function (datum) {
    return key in datum;
  }).length;
  var total = data.length;
  return {
    valid: valid,
    total: total
  };
};

var checkData = function checkData(data, dataKeys) {
  var dataIsObject = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  var optionalKeys = arguments.length > 3 ? arguments[3] : undefined;
  var results = {};
  var isArray = Array.isArray(data) && Array.isArray(dataKeys);
  var validType = !dataIsObject && isArray || dataIsObject && !isArray;
  results.invalidType = !validType;
  var dataAsArray = dataIsObject ? [data] : data;
  var keyChecks = validType && dataKeys.map(function (key) {
    results[key] = checkKey(dataAsArray, key, optionalKeys);
    return checkKey(dataAsArray, key, optionalKeys);
  });
  results.allKeysValid = validType && keyChecks.every(function (key) {
    return key.valid === key.total;
  });
  return results;
};

var _default = checkData;
exports["default"] = _default;