Skip to main content

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Downloads1/wk
Published2 years ago (0.215.0)
function mapKeys
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.

Examples

Example 1

import { mapKeys } from "@std/collections/map_keys";
import { assertEquals } from "@std/assert/assert_equals";

const counts = { a: 5, b: 3, c: 8 };

assertEquals(
  mapKeys(counts, (it) => it.toUpperCase()),
  {
    A: 5,
    B: 3,
    C: 8,
  },
);

Type Parameters

Parameters

record: Readonly<Record<string, T>>
transformer: (key: string) => string

Return Type

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/collections

Import symbol

import { mapKeys } from "@std/collections";
or

Import directly with a jsr specifier

import { mapKeys } from "jsr:@std/collections";