← Back to all products

TypeScript Utility Library

$29

Type-safe utility functions, custom hooks, generic patterns, and advanced TypeScript techniques with full test coverage.

24 files
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 Sample

File 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/`)

ModuleFunctionsDescription
array.ts12 functionsType-safe array operations (chunk, unique, groupBy, partition, zip, etc.)
object.ts10 functionsDeep clone, pick, omit, merge, diff, flatten nested objects
string.ts10 functionsslugify, truncate, template literals, case conversion, fuzzy match
async.ts8 functionsretry, debounce, throttle, timeout, queue, parallel limit
result.ts15 methodsResult and Option monads for error handling without try/catch
branded.ts8 typesBranded/nominal types for domain-safe IDs, emails, URLs
guards.ts12 guardsRuntime type guards with type narrowing (isString, isNonEmpty, etc.)

Custom Hooks (`src/hooks/`)

HookDescription
useLocalStoragePersistent state with JSON serialization and SSR safety
useDebounceDebounced value with configurable delay
usePreviousTrack the previous value of any variable
useMediaQueryReactive CSS media query matching
useEventListenerType-safe event listener with automatic cleanup
useIntervalsetInterval with pause/resume and React-safe cleanup
useOnClickOutsideDetect clicks outside a ref element
useIsomorphicLayoutEffectSSR-safe useLayoutEffect

Advanced Patterns (`src/patterns/`)

PatternDescription
BuilderType-safe builder pattern with method chaining
EventEmitterTyped event system with subscribe/unsubscribe
StateMachineFinite state machine with typed transitions
RegistryType-safe service/component registry
PipelineComposable 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 ...