mapFields
Accepts an obj object and a mapper function, iterates over each field of the object, and returns a new object whose values are the return values of mapper.
Added in v0.0.6
Usage
ts
import { mapFields } from 'parsnip-kit'
const input = { name: 'alice', city: 'tokyo' } as const
const result = mapFields(input, (v) => v.length)
// { name: 5, city: 5 }API
Type Parameter
| Arg | Type | Description |
|---|---|---|
T | extends object | Object type |
V | | The return type iterator function |
Arguments
| Arg | Type | Optional | Default | Description |
|---|---|---|---|---|
obj | T | false | undefined | Object to iterate |
mapper | <K extends keyof T>(value: T[K], key: K, object: T) => V | false | undefined | The Iterator function |
Returns
| Type |
|---|
Record<keyof T, V> |