Radash Utility Library

12.1.1 · active · verified Sun Apr 19

Radash is a modern, functional utility library for JavaScript and TypeScript, providing a comprehensive collection of helper functions with zero external dependencies. It's designed to be simple, powerful, and fully typed, offering alternatives to functions found in older libraries like Lodash while focusing on a smaller bundle size and native ESM support. The library is actively maintained, currently on version 12.1.1, with frequent minor and patch releases. Key differentiators include its strong, native TypeScript typing, which aims to improve type safety compared to libraries that often require extra type packages, and a modular design that facilitates tree-shaking for optimized bundle sizes. Radash focuses on functions that augment modern JavaScript features, intentionally omitting those already well-covered by the language itself, leading to a cleaner and more intuitive API.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates core Radash functionalities including array manipulation (`max`, `sum`), object transformation (`objectify`, `pick`), and robust asynchronous error handling (`tryit`).

import * as _ from 'radash'

const gods = [{
  name: 'Ra',
  power: 'sun',
  rank: 100,
  culture: 'egypt'
}, {
  name: 'Loki',
  power: 'tricks',
  rank: 72,
  culture: 'norse'
}, {
  name: 'Zeus',
  power: 'lightning',
  rank: 96,
  culture: 'greek'
}]

// Basic array operations
console.log('Max rank god:', _.max(gods, g => g.rank));
console.log('Total rank sum:', _.sum(gods, g => g.rank));

// Object manipulation
const godObject = _.objectify(
  gods, 
  g => g.name.toLowerCase(), 
  g => _.pick(g, ['power', 'rank', 'culture'])
);
console.log('Gods as object:', godObject);

// Asynchronous operations with error handling
const mockApi = {
  gods: {
    findByName: async (name) => {
      if (name === 'loki') throw new Error('Loki is elusive');
      return gods.find(g => g.name.toLowerCase() === name);
    }
  }
};

async function fetchAndLogGod(name) {
  const [err, god] = await _.try(mockApi.gods.findByName)(name);
  if (err) {
    console.error(`Failed to fetch ${name}:`, err.message);
  } else {
    console.log(`Fetched ${name}:`, god);
  }
}

fetchAndLogGod('ra');
fetchAndLogGod('loki');

view raw JSON →