Advanced Throttle Utility with Configurable Leading and Trailing Calls
Extend the basic throttle function to accept an options object with leading and trailing boolean flags. When leading is true, the function fires immediately on the first call; when trailing is true, it fires once more after the wait period ends with the latest arguments. Handle edge cases like both flags being false, rapid successive calls, and timer cleanup on cancel. This is the exact behavior used in lodash's throttle and Underscore.js.