/**
 * @module tgam-dom-methods
 */

/**
 * @method toArray
 * @description converts and array like (nodelist) to an array
 * @param val {Array|NodeList}
 * @return {Array}
 */
export function toArray(val) {
  if (typeof val === "undefined") {
    return null;
  } else if (typeof Array.from !== "undefined") {
    return Array.from(val);
  } else {
    return [].slice.call(val);
  }
}

/**
 * @method getScrollbarWidth
 * @description gets the scrollbar width
 * @return {number}
 */
export function getScrollbarWidth() {
  var scrollDiv = document.createElement("div");
  scrollDiv.className = "u-scrollbar-measure";
  document.body.appendChild(scrollDiv);

  const scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;

  document.body.removeChild(scrollDiv);

  return scrollbarWidth;
}
