VDL Plugin SDK

mapKeys

Import from @varavel/vdl-plugin-sdk/utils/objects.

function mapKeys<T, K>(object, getNewKey): Record<K, T[keyof T]>;

Creates a new object with the same values as the given object, but with keys generated by running each own enumerable property of the object through the iteratee function.

Type Parameters

Type ParameterDescription
T extends Record<PropertyKey, any>The type of the object.
K extends PropertyKeyThe type of the new keys generated by the iteratee function.

Parameters

ParameterTypeDescription
objectTThe object to iterate over.
getNewKey(value, key, object) => KThe function invoked per own enumerable property.

Returns

Record<K, T[keyof T]>

Returns the new mapped object.

Example

// Example usage:
const obj = { a: 1, b: 2 };
const result = mapKeys(obj, (value, key) => key + value);
console.log(result); // { a1: 1, b2: 2 }