"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.throttle = void 0;

const throttle = (callback, wait, leading = false) => {
  let timeout = null;
  let hasRun = false;

  const fn = (...args) => {
    if (!hasRun && leading) {
      callback(...args);
      hasRun = true;
      return;
    }

    if (!timeout) {
      timeout = setTimeout(() => {
        callback(...args);
        clearTimeout(timeout);
        timeout = null;
      }, wait);
    }
  };

  return fn;
};

exports.throttle = throttle;