JSON.tryParse = (value: any) => {
  try {
    var source = JSON.parse(value);
    return source;
  } catch (e) {
    return null;
  }
};
JSON.redirectFormat = function(
  data = [],
  message = "",
  status = 1,
  code = 200,
  extend: {}
) {
  return {
    code: code,
    data: data,
    message: message,
    status: status,
    ...extend,
  };
};

Array.prototype.order = function(childkey?: string) {
  let source = this;
  let result = source.concat([]);
  return reverse(result);
  function reverse(array: any) {
    let temp = new Array(array.length);
    for (let i = 0; i < array.length; i++) {
      if (childkey && array[i][childkey].length > 0) {
        array[i] = reverse(array[i][childkey]);
      }
      temp[array.length - i - 1] = array[i];
    }
    return temp;
  }
};
Array.prototype.insertAt = function(index: number, value: any) {
  this.splice(index, 0, value);
};
Array.prototype.removeAt = function(index: number) {
  this.splice(index, 1);
};
Array.prototype.remove = function(value: any) {
  let index = this.indexOf(value);
  if (index > -1) {
    this.splice(index, 1);
  }
};
Array.prototype.removeAll = function(value: any) {
  let status = false;
  let index = -1;
  while (status) {
    index = this.indexOf(value);
    if (index > -1) {
      this.splice(index, 1);
    } else {
      status = true;
    }
  }
};
Array.prototype.clear = function() {
  this.splice(0, this.length);
};
String.prototype.numberFormat = function(): number {
  let result = "";
  let _this = this;
  let _r = "";
  let chars = _this.split("");
  for (let index = 0; index < chars.length; index++) {
    if (!isNaN(parseInt(chars[index]))) {
      result += chars[index].toString();
    }
  }
  // value.split('');
  return parseInt(result);
};
window.isNumber = function(value: any): boolean {
  let _r = parseFloat(value.toString());
  return !isNaN(_r);
};
window.getPropertyValue = function(
  obj: any,
  keys: Array<string> | string
): any {
  return (
    (!Array.isArray(keys)
      ? keys
          .replace(/\[/g, ".")
          .replace(/\]/g, "")
          .split(".")
      : keys
    ).reduce((o: any, k: any) => (o || {})[k], obj) || null
  );
};
