<commit_before>interface DebounceOptions {
  maxWait?: number;
  leading?: boolean;
  trailing?: boolean;
}

export interface IDebounceReturn {
  cancel: () => void;
  flush: () => void;
  isPending: () => boolean;
}

export interface DebouncedReturn<T extends (...args: any[]) => ReturnType<T>> extends IDebounceReturn {
  (...args: Parameters<T>): ReturnType<T> | undefined;
}

export function debounce<T extends (...args: any) => ReturnType<T>>(fn: T, wait?: number, options?: DebounceOptions): DebouncedReturn<T> {

  let lastArgs;
  let lastThis: unknown;
  let timerId;
  let lastCallTime;
  let lastInvokeTime = 0;
  let leading = false;
  let maxing = false;
  let trailing = true;
  let result: ReturnType<T>;

  const useRAF = !wait && wait !== 0 && typeof window !== 'undefined' && typeof window.requestAnimationFrame === 'function';

  wait = +wait! || 0;
  options = options || {};

  leading = !!options.leading;
  trailing = 'trailing' in options ? !!options.trailing : true;
  maxing = 'maxWait' in options;
  const maxWait = maxing ? Math.max(+options.maxWait! || 0, wait) : null;
<commit_msg>chore(utils): add type checking only for function<commit_after>interface DebounceOptions {
  maxWait?: number;
  leading?: boolean;
  trailing?: boolean;
}

export interface IDebounceReturn {
  cancel: () => void;
  flush: () => void;
  isPending: () => boolean;
}

export interface DebouncedReturn<T extends (...args: any[]) => ReturnType<T>> extends IDebounceReturn {
  (...args: Parameters<T>): ReturnType<T> | undefined;
}

export function debounce<T extends (...args: any) => ReturnType<T>>(fn: T, wait?: number, options?: DebounceOptions): DebouncedReturn<T> {

  let lastArgs;
  let lastThis: unknown;
  let timerId;
  let lastCallTime;
  let lastInvokeTime = 0;
  let leading = false;
  let maxing = false;
  let trailing = true;
  let result;

  const useRAF = !wait && wait !== 0 && typeof window !== 'undefined' && typeof window.requestAnimationFrame === 'function';

  if (typeof fn !== 'function') {
    throw new TypeError('Expected a function')
  }

  wait = +wait! || 0;
  options = options || {};

  leading = !!options.leading;
  trailing = 'trailing' in options ? !!options.trailing : true;
  maxing = 'maxWait' in options;
  const maxWait = maxing ? Math.max(+options.maxWait! || 0, wait) : null;

{'fraction_non_alphanumeric': 0.15255694026643749, 'fraction_numerical': 0.0034379028792436614, 'mean_word_length': 4.208053691275167, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2810874', 'n_tokens_mistral': 740, 'n_tokens_neox': 724, 'n_words': 218}