Functional utility library - modern, simple, typed, powerful
Radash is a functional utility library built specifically for modern JavaScript and TypeScript projects. With over 936,000 weekly downloads, it provides a comprehensive set of helper functions for common operations like array manipulation, object transformation, async handling, and type checking. Unlike legacy alternatives, Radash is designed for contemporary codebases that already leverage ES6+ features, meaning it doesn't reimplement native methods like map or filter.
The library emphasizes three core principles: TypeScript-first design with proper type inference, zero runtime dependencies for minimal bundle size (306KB total), and full tree-shakability for optimal performance. Every function is typed to work seamlessly with TypeScript's type system, providing autocomplete and compile-time safety that plain JavaScript utilities lack. This makes it particularly valuable for teams building type-safe applications.
Radash organizes its utilities into logical categories: Array (range generation, grouping, sampling), Object (key mapping, deep cloning, picking), String (case conversion, templating), Async (try-catch wrappers, retry logic, parallel execution), Typed (runtime type guards), Curry (function composition), Number (rounding, clamping), and Random (UUID generation, shuffling). The API is intentionally minimalist, excluding operations already handled well by native JavaScript while adding genuinely useful abstractions for complex tasks.
Developers choose Radash when they need utility functions without the bloat of older libraries. It's particularly popular in performance-sensitive applications, serverless functions, and frontend projects where bundle size directly impacts load time. The library maintained active development through version 12.1.1, focusing on stability and TypeScript compatibility rather than chasing feature parity with heavyweight alternatives.
import { try as tryFn, parallel, objectify, group } from 'radash';
interface User {
id: string;
name: string;
role: 'admin' | 'user';
}
async function fetchUsers(ids: string[]): Promise<User[]> {
// Fetch users in parallel with max 3 concurrent requests
const results = await parallel(3, ids, async (id) => {
const [err, user] = await tryFn(async () => {
const res = await fetch(`/api/users/${id}`);
if (!res.ok) throw new Error('Failed to fetch');
return res.json() as Promise<User>;
})();
// Returns error or user - no exceptions thrown
return err ? null : user;
});
// Filter out failed requests
const users = results.filter((u): u is User => u !== null);
// Group users by role
const byRole = group(users, u => u.role);
// Create lookup map by ID
const userMap = objectify(
users,
u => u.id,
u => u
);
console.log('Admins:', byRole.admin?.length ?? 0);
console.log('User map keys:', Object.keys(userMap));
return users;
}
fetchUsers(['1', '2', '3']);Error handling in async functions: Radash's try() wrapper converts promise rejections into error-first tuples, eliminating nested try-catch blocks. Instead of wrapping API calls in verbose error handling, you get clean [error, result] destructuring that's easier to test and reason about.
Generating structured data for testing: The list() function creates arrays with custom mapping logic, perfect for seeding databases or generating mock data. Combined with range(), you can quickly build test fixtures with realistic patterns without manual loops.
Type-safe object transformations: When reshaping API responses or normalizing data structures, functions like objectify() and mapEntries() provide type-safe alternatives to manual reduce operations. TypeScript correctly infers key and value types throughout the transformation.
Retry logic for flaky network requests: The retry() function handles exponential backoff and conditional retries without implementing custom recursion. Particularly useful for third-party API integrations where transient failures are expected.
Parallel async operations with control: Unlike Promise.all which fails fast, Radash's parallel() function allows concurrent execution with configurable limits and error collection, ideal for batch processing or concurrent API requests where you need granular control over concurrency and failure handling.
npm install radashpnpm add radashbun add radash