mapFields
obj オブジェクトと mapper 関数を受け取り、オブジェクトの各フィールドを反復処理して、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 | オブジェクト型 |
V | | イテレータ関数の戻り型 |
Arguments
| Arg | Type | Optional | Default | Description |
|---|---|---|---|---|
obj | T | false | undefined | 反復するオブジェクト |
mapper | <K extends keyof T>(value: T[K], key: K, object: T) => V | false | undefined | イテレータ関数 |
Returns
| Type |
|---|
Record<keyof T, V> |