rangeMap & mapRange
Generates mapped numeric arrays for iterations and maps numbers across ranges with linear interpolation.
2.8 KB
•Updated on September 3, 2026
Example 2: Linear Range Interpolation (mapRange)
Installation
Bash
pnpm dlx shadcn@latest add @spaceui/hooks-utils-range-mapUsage
Code
import { rangeMap, range, mapRange } from '@/utils/range-map'
rangeMap(5, (i) => i * 2) // => [0, 2, 4, 6, 8]
rangeMap({ n: 3, fn: (i) => i + 1 }) // => [1, 2, 3]
mapRange(0.5, 0, 1, 0, 100) // => 50API Reference
Parameters / Props
| Parameter | Type | Default | Description |
|---|---|---|---|
countOrOptions | number|RangeMapOptions<T> | required | Total element count or options object. |
mapFn | (index: number) => T | - | Optional transformation function. |
Return Value
| Return Type | Description |
|---|---|
T[] | Generated and mapped array. |