trickster

library pkg

Overview

Trickster is a lightweight utility library for advanced JavaScript tricks and patterns.

Installation

npm install trickster
# or
pnpm add trickster

Core Features

Debounce Utility

Control function execution frequency:

import { debounce } from 'trickster';

const debouncedSearch = debounce((query: string) => {
  console.log('Searching for:', query);
}, 300);

// Usage
debouncedSearch('react');
debouncedSearch('typescript'); // Only this will execute after 300ms

Throttle Utility

Limit function execution rate:

import { throttle } from 'trickster';

const throttledScroll = throttle(() => {
  console.log('Scroll event handled');
}, 100);

window.addEventListener('scroll', throttledScroll);

Advanced Patterns

Memoization

Cache expensive computations:

import { memoize } from 'trickster';

const expensiveFunction = memoize((n: number) => {
  // Expensive computation
  return n * n;
});

console.log(expensiveFunction(5)); // Computed
console.log(expensiveFunction(5)); // Cached result

API Reference

Functions

debounce(fn, delay)

Creates a debounced version of the provided function.

Parameters:

  • fn: Function to debounce
  • delay: Delay in milliseconds

Returns: Debounced function

throttle(fn, interval)

Creates a throttled version of the provided function.

Parameters:

  • fn: Function to throttle
  • interval: Interval in milliseconds

Returns: Throttled function

Examples

Check out our examples repository for more usage patterns.

More Projects

Explore other projects that might interest you

View all