UNPKG

@onesy/utils

Version:
23 lines (22 loc) 622 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // every 100ms at least const throttle = (method, interval = 100) => { let lastTime = 0; let timeoutID; return function (...args) { const now = Date.now(); if (now - lastTime >= interval) { lastTime = now; method(...args); } else { clearTimeout(timeoutID); timeoutID = setTimeout(() => { lastTime = Date.now(); method(...args); }, interval - (now - lastTime)); } }; }; exports.default = throttle;