← Back to all products
$29
TypeScript Utility Library
Type-safe utility functions, custom hooks, generic patterns, and advanced TypeScript techniques with full test coverage.
TypeScriptMarkdownJSONReact
Product Preview
Try the interactive reader and demo tools below, or get the full product with all content unlocked.
Interactive Reader (Free Preview) ⚙ Try Demo Tools Download Free SampleFile Structure 24 files
typescript-utility-library/
├── LICENSE
├── README.md
├── examples/
│ └── real-world.ts
├── free-sample.zip
├── guide/
│ └── type-patterns.md
├── guides/
│ └── type-patterns.md
├── index.html
├── interactive.html
├── package.json
├── src/
│ ├── array.ts
│ ├── async.ts
│ ├── branded.ts
│ ├── guards.ts
│ ├── hooks/
│ │ └── index.ts
│ ├── index.ts
│ ├── object.ts
│ ├── patterns/
│ │ └── index.ts
│ ├── result.ts
│ └── string.ts
├── tests/
│ ├── array.test.ts
│ └── result.test.ts
├── tsconfig.json
└── vitest.config.ts
Documentation Preview README excerpt
TypeScript Utility Library
A collection of type-safe utilities, custom hooks, and advanced TypeScript patterns for modern React/TypeScript applications. Everything is thoroughly typed with generics, and every function includes JSDoc documentation.
What's Included
Core Utilities (`src/`)
| Module | Functions | Description |
|---|---|---|
array.ts | 12 functions | Type-safe array operations (chunk, unique, groupBy, partition, zip, etc.) |
object.ts | 10 functions | Deep clone, pick, omit, merge, diff, flatten nested objects |
string.ts | 10 functions | slugify, truncate, template literals, case conversion, fuzzy match |
async.ts | 8 functions | retry, debounce, throttle, timeout, queue, parallel limit |
result.ts | 15 methods | Result and Option monads for error handling without try/catch |
branded.ts | 8 types | Branded/nominal types for domain-safe IDs, emails, URLs |
guards.ts | 12 guards | Runtime type guards with type narrowing (isString, isNonEmpty, etc.) |
Custom Hooks (`src/hooks/`)
| Hook | Description |
|---|---|
useLocalStorage | Persistent state with JSON serialization and SSR safety |
useDebounce | Debounced value with configurable delay |
usePrevious | Track the previous value of any variable |
useMediaQuery | Reactive CSS media query matching |
useEventListener | Type-safe event listener with automatic cleanup |
useInterval | setInterval with pause/resume and React-safe cleanup |
useOnClickOutside | Detect clicks outside a ref element |
useIsomorphicLayoutEffect | SSR-safe useLayoutEffect |
Advanced Patterns (`src/patterns/`)
| Pattern | Description |
|---|---|
Builder | Type-safe builder pattern with method chaining |
EventEmitter | Typed event system with subscribe/unsubscribe |
StateMachine | Finite state machine with typed transitions |
Registry | Type-safe service/component registry |
Pipeline | Composable data transformation pipelines |
Quick Start
# Copy the files you need into your project
cp -r typescript-utility-library/src/ your-project/src/utils/
# Or cherry-pick individual modules
cp typescript-utility-library/src/result.ts your-project/src/utils/
// Import what you need
import { Result, Ok, Err } from "./utils/result";
import { chunk, unique, groupBy } from "./utils/array";
import { useDebounce, useLocalStorage } from "./utils/hooks";
import type { Email, UserId } from "./utils/branded";
Running Tests
... continues with setup instructions, usage examples, and more.
Code Sample .ts preview
src/array.ts
// ============================================================================
// Array Utilities — Type-safe array transformations and queries
// ============================================================================
//
// These functions fill gaps in the native Array prototype without monkey-patching.
// Every function is generic, preserves readonly arrays where possible, and never
// mutates the input. The naming follows established conventions from lodash/ramda
// so the learning curve is minimal.
//
// Why not just use lodash?
// 1. Tree-shaking still pulls in shared internals — these are zero-dependency.
// 2. Lodash types are "best effort" — these are *designed* for TypeScript first.
// 3. You can read and modify every line; no 200-file dependency graph.
// ---------------------------------------------------------------------------
// chunk — split an array into fixed-size groups
// ---------------------------------------------------------------------------
// Useful for: batch processing, paginating in-memory data, grid layouts.
// The last chunk may be smaller than `size` if the array length isn't divisible.
export function chunk<T>(array: readonly T[], size: number): T[][] {
if (size < 1) {
throw new RangeError(`chunk size must be >= 1, got ${size}`);
}
const result: T[][] = [];
for (let i = 0; i < array.length; i += size) {
result.push(array.slice(i, i + size));
}
return result;
}
// ---------------------------------------------------------------------------
// unique — remove duplicate values (by identity or key function)
// ---------------------------------------------------------------------------
// The optional `keyFn` lets you deduplicate objects by a computed key.
// First occurrence wins — order is preserved.
export function unique<T>(array: readonly T[]): T[];
export function unique<T, K>(array: readonly T[], keyFn: (item: T) => K): T[];
export function unique<T, K>(
array: readonly T[],
keyFn?: (item: T) => K,
): T[] {
if (!keyFn) {
// Fast path: primitives or reference equality
return [...new Set(array)];
}
const seen = new Set<K>();
# ... 322 more lines ...