radash Installation
npm
bash
npm install radash
yarn
bash
yarn add radash
pnpm
bash
pnpm add radash
Usage
ES6 Modules
typescript
import { range, tryit } from 'radash'
// Using range function
for (const i of range(0, 4)) {
console.log(i) // 0, 1, 2, 3, 4
}
// Using tryit function
const [err, response] = await tryit(api.gods.create)({ name: 'Ra' })
if (err) {
throw new Error('Your god is weak and could not be created')
}
CommonJS
javascript
const { range, tryit } = require('radash')
// Using range function
for (const i of range(0, 4)) {
console.log(i) // 0, 1, 2, 3, 4
}
// Using tryit function
const [err, response] = await tryit(api.gods.create)({ name: 'Ra' })
if (err) {
throw new Error('Your god is weak and could not be created')
}
Browser Usage
CDN
html
<script src="https://unpkg.com/radash@latest/dist/index.umd.js"></script>
<script>
const { range, tryit } = window.radash
// Using functions
for (const i of range(0, 4)) {
console.log(i) // 0, 1, 2, 3, 4
}
</script>
ES6 Modules (CDN)
html
<script type="module">
import { range, tryit } from 'https://unpkg.com/radash@latest/dist/index.esm.js'
// Using functions
for (const i of range(0, 4)) {
console.log(i) // 0, 1, 2, 3, 4
}
</script>
TypeScript Support
Radash fully supports TypeScript, with complete type definitions for all functions.
typescript
import { range, tryit, select } from 'radash'
// Type-safe range function
const numbers: number[] = Array.from(range(0, 10))
// Type-safe tryit function
const [err, result] = await tryit(async () => {
return await fetch('/api/data')
})
// Type-safe select function
const users = [
{ id: 1, name: 'Alice', age: 25 },
{ id: 2, name: 'Bob', age: 30 },
{ id: 3, name: 'Charlie', age: 35 }
]
const adultUsers = select(users,
user => ({ ...user, isAdult: true }),
user => user.age >= 18
)
Environment Requirements
- Node.js >= 14.0.0
- Modern browsers supporting ES6 modules
Quick Start
After installation, you can immediately start using Radash's powerful features:
typescript
import { range, tryit, select, objectify } from 'radash'
// 1. Using range for iteration
for (const i of range(0, 10, 2)) {
console.log(i) // 0, 2, 4, 6, 8, 10
}
// 2. Using tryit for error handling
const [err, data] = await tryit(fetch)('/api/users')
if (err) {
console.error('Failed to fetch users:', err)
return
}
// 3. Using select for data transformation and filtering
const users = await data.json()
const activeUsers = select(users,
user => ({ ...user, status: 'active' }),
user => user.isActive
)
// 4. Using objectify to convert arrays to objects
const usersById = objectify(users,
user => user.id,
user => user.name
)
Radash provides 100+ utility functions covering arrays, objects, strings, numbers, asynchronous operations, and more, helping you write JavaScript/TypeScript code more efficiently.