Skip to content

Migration Guide ​

This guide will help you smoothly migrate from Lodash to Radash, including common function mappings, migration steps, and best practices.

Why Choose Radash? ​

Feature Comparison ​

FeatureRadashLodash
Bundle SizeZero dependencies, smaller sizeHas dependencies, larger size
TypeScript SupportNative support, type-safeRequires additional type packages
ModernizationUses modern JS featuresCompatible with older browsers
PerformanceOptimized modern implementationCompatibility prioritized
Maintenance StatusActively maintainedRelatively lagging maintenance

Migration Steps ​

1. Install Radash ​

bash
# Install Radash
npm install radash

# Optional: Keep Lodash for comparison testing
npm install lodash @types/lodash

2. Update Import Statements ​

From Lodash Imports ​

typescript
// Old way - Lodash
import _ from 'lodash'
import { map, filter, debounce } from 'lodash'

Migrate to Radash Imports ​

typescript
// New way - Radash
import { map, filter, debounce } from 'radash'

// Or import on-demand
import { map } from 'radash/array'
import { debounce } from 'radash/curry'

3. Function Mapping Table ​

Array Operation Functions ​

Lodash FunctionRadash FunctionDescription
_.map()map()Array mapping
_.filter()filter()Array filtering
_.reduce()reduce()Array reduction
_.find()find()Find element
_.findIndex()findIndex()Find index
_.some()some()Partial matching
_.every()every()All matching
_.includes()includes()Inclusion check
_.uniq()unique()Remove duplicates
_.flatten()flat()Array flattening
_.chunk()chunk()Array chunking
_.range()range()Range generation

Object Operation Functions ​

Lodash FunctionRadash FunctionDescription
_.get()get()Safe property access
_.set()set()Safe property setting
_.pick()pick()Select properties
_.omit()omit()Exclude properties
_.cloneDeep()clone()Deep cloning
_.merge()merge()Object merging
_.keys()keys()Get keys
_.values()values()Get values
_.entries()entries()Get key-value pairs

Functional Programming Tools ​

Lodash FunctionRadash FunctionDescription
_.debounce()debounce()Debouncing
_.throttle()throttle()Throttling
_.memoize()memo()Memoization
_.compose()compose()Function composition
_.curry()curry()Currying

Type Checking Functions ​

Lodash FunctionRadash FunctionDescription
_.isArray()isArray()Array check
_.isObject()isObject()Object check
_.isString()isString()String check
_.isNumber()isNumber()Number check
_.isFunction()isFunction()Function check
_.isEmpty()isEmpty()Empty value check

Migration Examples ​

Array Operation Migration ​

From Lodash Migration ​

typescript
import _ from 'lodash'

const users = [
  { id: 1, name: 'Alice', age: 25 },
  { id: 2, name: 'Bob', age: 30 },
  { id: 3, name: 'Charlie', age: 35 }
]

// Lodash way
const names = _.map(users, 'name')
const adults = _.filter(users, { age: { $gte: 30 } })
const totalAge = _.sumBy(users, 'age')
const uniqueAges = _.uniq(_.map(users, 'age'))

Migrate to Radash ​

typescript
import { map, filter, reduce, unique } from 'radash'

const users = [
  { id: 1, name: 'Alice', age: 25 },
  { id: 2, name: 'Bob', age: 30 },
  { id: 3, name: 'Charlie', age: 35 }
]

// Radash way
const names = map(users, user => user.name)
const adults = filter(users, user => user.age >= 30)
const totalAge = reduce(users, (sum, user) => sum + user.age, 0)
const uniqueAges = unique(map(users, user => user.age))

Object Operation Migration ​

From Lodash Migration ​

typescript
import _ from 'lodash'

const user = {
  name: 'Alice',
  age: 25,
  address: {
    city: 'New York',
    country: 'USA'
  }
}

// Lodash way
const city = _.get(user, 'address.city', 'Unknown')
const userInfo = _.pick(user, ['name', 'age'])
const userWithoutAge = _.omit(user, ['age'])
const clonedUser = _.cloneDeep(user)

Migrate to Radash ​

typescript
import { get, pick, omit, clone } from 'radash'

const user = {
  name: 'Alice',
  age: 25,
  address: {
    city: 'New York',
    country: 'USA'
  }
}

// Radash way
const city = get(user, 'address.city', 'Unknown')
const userInfo = pick(user, ['name', 'age'])
const userWithoutAge = omit(user, ['age'])
const clonedUser = clone(user)

Function Tool Migration ​

From Lodash Migration ​

typescript
import _ from 'lodash'

// Lodash way
const debouncedSearch = _.debounce(searchFunction, 300)
const throttledScroll = _.throttle(scrollHandler, 100)
const memoizedCalc = _.memoize(expensiveCalculation)

Migrate to Radash ​

typescript
import { debounce, throttle, memo } from 'radash'

// Radash way
const debouncedSearch = debounce(searchFunction, 300)
const throttledScroll = throttle(scrollHandler, 100)
const memoizedCalc = memo(expensiveCalculation)

Chaining Operation Migration ​

Lodash Chaining ​

typescript
import _ from 'lodash'

const result = _(users)
  .filter(user => user.age >= 30)
  .map(user => user.name)
  .uniq()
  .value()

Radash Functional Approach ​

typescript
import { filter, map, unique } from 'radash'

const result = unique(
  map(
    filter(users, user => user.age >= 30),
    user => user.name
  )
)

Type Safety Improvements ​

Before Migration (Lodash) ​

typescript
import _ from 'lodash'

// Requires additional type handling
if (_.isArray(data)) {
  (data as any[]).forEach(item => console.log(item))
}

const result = _.map(users, 'name') // Inaccurate type inference

After Migration (Radash) ​

typescript
import { isArray, map } from 'radash'

// Complete type safety
if (isArray(data)) {
  data.forEach(item => console.log(item)) // TypeScript knows data is an array
}

const result = map(users, user => user.name) // Accurate type inference

Performance Optimization ​

Before Migration ​

typescript
import _ from 'lodash'

// Lodash's compatibility-first implementation
const largeArray = Array.from({ length: 100000 }, (_, i) => i)
const doubled = _.map(largeArray, n => n * 2)
const evens = _.filter(largeArray, n => n % 2 === 0)

After Migration ​

typescript
import { map, filter } from 'radash'

// Radash's optimized modern implementation
const largeArray = Array.from({ length: 100000 }, (_, i) => i)
const doubled = map(largeArray, n => n * 2)
const evens = filter(largeArray, n => n % 2 === 0)

Migration Checklist ​

Phase 1: Preparation ​

  • [ ] Backup current code
  • [ ] Install Radash
  • [ ] Create migration branch
  • [ ] Set up testing environment

Phase 2: Core Migration ​

  • [ ] Update import statements
  • [ ] Replace array operation functions
  • [ ] Replace object operation functions
  • [ ] Replace functional programming tools
  • [ ] Replace type checking functions

Phase 3: Optimization ​

  • [ ] Remove chaining operations
  • [ ] Optimize type definitions
  • [ ] Performance testing
  • [ ] Code review

Phase 4: Validation ​

  • [ ] Unit tests pass
  • [ ] Integration tests pass
  • [ ] Performance benchmarking
  • [ ] Production deployment

Frequently Asked Questions ​

Q: How to handle Lodash-specific features? ​

A: Some Lodash-specific features may require custom implementation or use of native JavaScript methods.

Q: Will migration affect performance? ​

A: Radash typically provides better performance, but it's recommended to run benchmark tests for verification.

Q: How to handle chaining operations? ​

A: Convert chaining operations to functional composition, or use Radash's compose function.

Q: Will TypeScript types be lost? ​

A: No, Radash provides better type safety and inference.

Summary ​

Migrating to Radash is a worthwhile investment that will bring to your project:

  • Smaller bundle size - Zero dependency design
  • Better type safety - Native TypeScript support
  • Higher performance - Optimized modern implementation
  • Cleaner API - Modern design philosophy

Following this guide, you will be able to smoothly transition from Lodash to Radash and enjoy a modern development experience.

Released under the MIT License.