# deep-key-mirror

> Alternative to React keyMirror

Latest version **0.8.0** (published 2026-06-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install deep-key-mirror
pnpm add deep-key-mirror
yarn add deep-key-mirror
bun add deep-key-mirror
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.8.0 |
| Published | 2026-06-23 |
| First published | 2015-11-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 16.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 6 |
| Author | tkqubo |
| Maintainers | tkqubo |
| Keywords | keymirror, key-mirror, deep-key-mirror, constants, enum, mirror, object-keys, typescript, react |

## Links

- npm: https://www.npmjs.com/package/deep-key-mirror
- Repository: https://github.com/tkqubo/deep-key-mirror
- Issues: https://github.com/tkqubo/deep-key-mirror/issues
- npm.io page: https://npm.io/package/deep-key-mirror

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.8.0 (latest) — 2026-06-23
- 0.7.0 — 2026-06-08
- 0.6.1 — 2024-07-16
- 0.6.0 — 2024-07-16
- 0.5.5 — 2024-07-16
- 0.5.4 — 2024-07-16
- 0.5.3 — 2024-07-16
- 0.5.2 — 2024-07-16
- 0.5.1 — 2024-07-16
- 0.5.0 — 2024-07-16
- 0.4.3 — 2022-02-14
- 0.4.2 — 2022-02-14
- 0.4.1 — 2022-02-14
- 0.4.0 — 2022-02-14
- 0.3.0 — 2022-02-14
- … 5 more at https://npm.io/package/deep-key-mirror/versions

## README

# Deep Key Mirror

[![npm version](https://img.shields.io/npm/v/deep-key-mirror?style=flat-square&logo=npm&color=CB3837)](https://www.npmjs.com/package/deep-key-mirror)
[![CI](https://img.shields.io/github/actions/workflow/status/tkqubo/deep-key-mirror/build.yml?style=flat-square&logo=githubactions&logoColor=white&label=CI)](https://github.com/tkqubo/deep-key-mirror/actions/workflows/build.yml)
[![codecov](https://img.shields.io/codecov/c/github/tkqubo/deep-key-mirror?style=flat-square&logo=codecov&logoColor=white)](https://codecov.io/gh/tkqubo/deep-key-mirror)
[![Bundle size](https://img.shields.io/bundlejs/size/deep-key-mirror?style=flat-square&label=minzip)](https://bundlejs.com/?q=deep-key-mirror)
[![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
[![License: MIT](https://img.shields.io/npm/l/deep-key-mirror?style=flat-square&color=blue)](./LICENSE)

Alternative to React's [keyMirror](https://github.com/STRML/keyMirror) which further mirrors properties deep inside the
object graph.

## Installation

```sh
npm install deep-key-mirror
```

## Usage

### `deepKeyMirror(obj)`

Returns a new object whose values equal the `.`-joined property paths in the given object.

#### Simple example

```ts
import deepKeyMirror from 'deep-key-mirror';

deepKeyMirror({ name: null, age: null }); // { name: 'name', age: 'age' }
```

#### String arrays

A **string array** is mirrored into an object keyed by its elements:

```ts
deepKeyMirror(['apple', 'banana', 'grape']);
// { apple: 'apple', banana: 'banana', grape: 'grape' }
```

#### Nested example

Child objects and string arrays are mirrored recursively, with the `.`-joined paths from the root assigned to each
value. (An array containing **objects** keeps the index-path behaviour instead, e.g. `items[0].name`.)

```ts
import deepKeyMirror from 'deep-key-mirror';

const breakfast = {
  bread: null,
  beverage: {
    milk: null,
    coffee: null,
    beer: 'BEER!',
  },
  fruits: ['orange', 'apple'],
};
const mirrored = deepKeyMirror(breakfast);
/*
mirrored === {
  bread: 'bread',
  beverage: {
    milk: 'beverage.milk',
    coffee: 'beverage.coffee',
    beer: 'beverage.beer',
  },
  fruits: {
    orange: 'fruits.orange',
    apple: 'fruits.apple',
  },
}
*/
```

#### Literal types

The return type is inferred as **literal types** when the argument is an inline literal (or annotated `as const`):

```ts
const keys = deepKeyMirror(['apple', 'banana']);
//    ^? { apple: 'apple'; banana: 'banana' }
```

When you pass a pre-declared variable, its array elements widen to `string[]`, so use an inline literal or `as const`
to retain literal keys.

## TypeScript

TypeDoc-generated documentation is available [here](http://tkqubo.github.io/deep-key-mirror/)

---
_Source: https://npm.io/package/deep-key-mirror · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
