"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.deepClone = deepClone;
exports.simpleMerge = simpleMerge;
exports.isArray = isArray;
exports.isFloat = isFloat;
exports.findIndex = findIndex;
exports.isPlainString = isPlainString;
exports.isNumericalValue = isNumericalValue;
exports.isFunction = isFunction;

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

/* eslint-disable no-prototype-builtins */

/**
 * 深拷贝
 * @param {*} obj
 */
function deepClone(obj) {
  var objClone = Array.isArray(obj) ? [] : {};

  if (obj && _typeof(obj) === 'object') {
    for (var key in obj) {
      if (obj.hasOwnProperty(key)) {
        if (obj[key] && _typeof(obj[key]) === 'object') {
          objClone[key] = deepClone(obj[key]);
        } else {
          objClone[key] = obj[key];
        }
      }
    }
  }

  return objClone;
}
/**
 * 对象属性合并
 * @param {*} target
 * @param {*} config
 * @param {*} copy
 */


function simpleMerge(target, config) {
  var copy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  if (Object.prototype.toString.call(config) !== '[object Object]') return target;
  var result = copy ? deepClone(target) : target;
  Object.keys(config).forEach(function (key) {
    if (config[key]) {
      result[key] = config[key];
    }
  });
  return result;
}
/**
 * 判断是否为数组
 * @param {*} target
 */


function isArray(target) {
  return Object.prototype.toString.call(target) === '[object Array]';
}

var floatRegex = /^[0-9]+\.?[0-9]+?$/;
/**
 * 判断是否为小数
 * @param {*} number
 */

function isFloat(number) {
  return floatRegex.test(number);
}

function findIndex(arr, item) {
  var i = arr.indexOf(item);
  return i === -1 ? '' : i;
}
/**
 * 普通字符串
 * @param
 */


function isPlainString(target) {
  var data = target;

  try {
    data = JSON.parse(target);
  } catch (e) {
    data = target;
  }

  return Object.prototype.toString.call(data) === '[object String]';
}
/**
 * 数值类型
 * @param
 */


function isNumericalValue(target) {
  return !isNaN(target);
}

function isFunction(target) {
  return Object.prototype.toString.call(target) === '[object Function]';
}

function getLanguage() {
  var _window$cb, _window$cb$lang, _window$cb2, _window$cb2$rest$AppC;

  var lang = "zh_CN";
  var globa = ((_window$cb = window.cb) === null || _window$cb === void 0 ? void 0 : (_window$cb$lang = _window$cb.lang) === null || _window$cb$lang === void 0 ? void 0 : _window$cb$lang.lang) || ((_window$cb2 = window.cb) === null || _window$cb2 === void 0 ? void 0 : (_window$cb2$rest$AppC = _window$cb2.rest.AppContext) === null || _window$cb2$rest$AppC === void 0 ? void 0 : _window$cb2$rest$AppC.globalization) || null;

  if (globa === null || globa === void 0 ? void 0 : globa.locale) {
    return globa.locale;
  }

  if (window && Url.query('locale')) {
    // url 配置页面语言
    lang = Url.query('locale');
  } else if (getCookie('locale')) {
    lang = getCookie('locale');
  } else if (globa === null || globa === void 0 ? void 0 : globa.locale) {
    lang = globa.locale;
  } else {// 系统浏览器语言
  }

  if (!lang) console.error('Please add the _lang parameter to the browser !');
  return lang;
} // function getCookie(name) {
//   const reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
//   const arr = document && document.cookie.match(reg)
//   if (arr) {
//     return unescape(arr[2]);
//   } else {
//     return null;
//   }
// }
// export function getLocale (key) {
//   let lang = getLanguage();
//   return Locale[lang]?Locale[lang][key]:Locale['zh_CN'][key];
// }
//# sourceMappingURL=index.js.map
