mapKeys
import { mapKeys } from "jsr:@ende/collections";function
function mapKeys<T>(record: Readonly<Record<string, T>>, transformer: (key: string) => string): Record<string, T>Applies the given transformer to all keys in the given record's entries and returns a new record containing the transformed entries.
If the transformed entries contain the same key multiple times, only the last one will appear in the returned record.
record: Readonly<Record<string, T>>The record to map keys from.
transformer: (key: string) => stringThe function to transform each key.
Returns
A new record with all keys transformed by the given transformer.
Example: Basic usage
import { mapKeys } from "@ende/collections/map-keys";
import { assertEquals } from "@ende/assert";
const counts = { a: 5, b: 3, c: 8 };
assertEquals(
mapKeys(counts, (key) => key.toUpperCase()),
{
A: 5,
B: 3,
C: 8,
},
);