trickster
Table of Contents
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 debouncedelay
: Delay in milliseconds
Returns: Debounced function
throttle(fn, interval)
Creates a throttled version of the provided function.
Parameters:
fn
: Function to throttleinterval
: 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
next-api-compose
Simple, dependency free, error aware and powerful utility to compose chain of multiple middleware into one Next.js API Route.
next-api-og-image
:bowtie: Easy way to generate open-graph images dynamically in HTML or React using Next.js API Routes. Suitable for serverless environment.
obj-serialize
Simple utility for serializing objects. Lightweight alternative to 'superjson'. Super useful in Next.js Pages Router