Skip to content

mapFields

Static Badge

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

ArgTypeDescription
Textends objectオブジェクト型
Vイテレータ関数の戻り型

Arguments

ArgTypeOptionalDefaultDescription
objTfalseundefined反復するオブジェクト
mapper<K extends keyof T>(value: T[K], key: K, object: T) => Vfalseundefinedイテレータ関数

Returns

Type
Record<keyof T, V>