export const truncate = (str, length) => {
  return str.substr(0, length - 1) + (str.length > length ? '...' : '');
};

export const dispatchCustomEvent = (elem, eventName, data) => {
  var event = new CustomEvent(eventName, { detail: data });
  document.dispatchEvent(event);
};

export const removeLabel = (arr, labelToRemove) => {
  arr.splice(
    arr.findIndex(
      (elem) => (
        elem.label === labelToRemove
      )), 1);
  return arr;
};