Skip to content

mapFields

Static Badge

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

ArgTypeDescription
Textends objectObject type
VThe return type iterator function

Arguments

ArgTypeOptionalDefaultDescription
objTfalseundefinedObject to iterate
mapper<K extends keyof T>(value: T[K], key: K, object: T) => VfalseundefinedThe Iterator function

Returns

Type
Record<keyof T, V>