npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

keymirrorprefix

v2.0.0

Published

A utility for creating an object with values equal to its keys, prefixed with a specified string.

Downloads

271

Readme

🔑 Key Mirror Prefix

Test

Node Versions Supported

A utility for creating an object with values equal to its keys, prefixed with a specified string. Ideal for Redux action types, analytics events, error codes, and other constants that need unique identifiers across modules.

Motivation

When building large or complex applications, managing constants like action types, event names, or error codes becomes repetitive and error-prone. Without prefixing, you either risk naming collisions across different areas of your app, or you manually add prefixes everywhere - leading to verbose, inconsistent code.

Key Mirror Prefix solves this by automatically prefixing groups of constants, ensuring uniqueness while keeping your code clean and maintainable. Whether you're building Redux actions, analytics events, or any other grouped constants, you get organised, collision-free identifiers with minimal effort.

Example

The Problem

Single object - verbose and error-prone:

import keyMirror from 'key-mirror'

export const REDUX_ACTIONS = keyMirror({
  CITIES_SEARCH_REQUEST: null,
  CITIES_SEARCH_SUCCESS: null,
  CITIES_SEARCH_FAILURE: null,
  COUNTRIES_SEARCH_REQUEST: null,
  COUNTRIES_SEARCH_SUCCESS: null,
  COUNTRIES_SEARCH_FAILURE: null,
})

console.log(REDUX_ACTIONS.CITIES_SEARCH_REQUEST) // "CITIES_SEARCH_REQUEST"
console.log(REDUX_ACTIONS.COUNTRIES_SEARCH_REQUEST) // "COUNTRIES_SEARCH_REQUEST"

Multiple objects - collision risk:

import keyMirror from 'key-mirror'

export const CITIES = keyMirror({
  SEARCH_REQUEST: null,
  SEARCH_SUCCESS: null,
  SEARCH_FAILURE: null,
})

export const COUNTRIES = keyMirror({
  SEARCH_REQUEST: null,
  SEARCH_SUCCESS: null,
  SEARCH_FAILURE: null,
})

console.log(CITIES.SEARCH_REQUEST) // "SEARCH_REQUEST"
console.log(COUNTRIES.SEARCH_REQUEST) // "SEARCH_REQUEST"

The Solution

Using Key Mirror Prefix - clean and collision-free:

import { keyMirrorPrefix } from 'keymirrorprefix'

export const CITIES = keyMirrorPrefix('CITIES', {
  SEARCH_REQUEST: null,
  SEARCH_SUCCESS: null,
  SEARCH_FAILURE: null,
})

export const COUNTRIES = keyMirrorPrefix('COUNTRIES', {
  SEARCH_REQUEST: null,
  SEARCH_SUCCESS: null,
  SEARCH_FAILURE: null,
})

console.log(CITIES.SEARCH_REQUEST) // "CITIES_SEARCH_REQUEST"
console.log(COUNTRIES.SEARCH_REQUEST) // "COUNTRIES_SEARCH_REQUEST"

Usage

Installation

Install the package as a dependency:

# Using npm
npm install keymirrorprefix

# Using yarn
yarn add keymirrorprefix

Importing

You can import keyMirrorPrefix using either CommonJS or ES Modules:

// Using CommonJS
const { keyMirrorPrefix } = require('keymirrorprefix')

// Using ES Modules
import { keyMirrorPrefix } from 'keymirrorprefix'

Basic Usage

Once you've imported keyMirrorPrefix, you can use it to create an object with keys mirrored as values, prefixed with a specified string:

const NAVIGATION = keyMirrorPrefix('NAVIGATION', {
  CLICK: null,
  CLOSE: null,
  OPEN: null,
})

const PANEL = keyMirrorPrefix('PANEL', {
  CLOSE: null,
  OPEN: null,
})

console.log(NAVIGATION.OPEN) // "NAVIGATION_OPEN"
console.log(PANEL.OPEN) // "PANEL_OPEN"

Usage Without Prefix

If you do not need a prefix, you can either pass null as the first argument to keyMirrorPrefix, or you can import and use keyMirror:

import { keyMirror, keyMirrorPrefix } from 'keymirrorprefix'

const ANALYTICS = keyMirrorPrefix(null, {
  SEARCH: null,
  SIGN_OUT: null,
})

const EVENTS = keyMirror({
  BLUR: null,
  FOCUS: null,
})

console.log(ANALYTICS.SEARCH) // "SEARCH"
console.log(EVENTS.BLUR) // "BLUR"