export class Utils {

  static debounce(func, wait, immediate = false) {
    let timeout;
    return (...args) => {
      let later = () => {
        timeout = null;
        if (!immediate) {
          func.apply(this, args)
        };
      };
      let callNow = immediate && !timeout;
      clearTimeout(timeout);
      timeout = setTimeout(later, wait);
      if (callNow) {
        func.apply(this, args)
      };
    };
  }

  static isTouchDevice(): boolean {
    try {
      document.createEvent('TouchEvent');
      return true;
    } catch (e) {
      return false;
    }
  }

  static toggleNoScrollBodyState(): void {
    if (document.body.classList.contains('no-scroll')) {
      document.body.classList.remove('no-scroll');
    } else {
      document.body.classList.add('no-scroll');
    }
  }

}
