A simple utility for creating an object with values equal to its keys. Identical to react/lib/keyMirror
Last updated 6 years ago by strml .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install keymirror 
SYNC missed versions from official npm registry.


Create an object with values equal to its key names.

I thought react/lib/keyMirror was useful and wanted to reuse it without any dependencies.

This is not my code, this is property of Facebook.


npm install keymirror

var keyMirror = require('keyMirror');
var COLORS = keyMirror({blue: null, red: null});
var myColor =;
var isColorValid = !!COLORS[myColor];

The last line could not be performed if the values of the generated enum were not equal to their keys.

Input: {key1: val1, key2: val2}

Output: {key1: key1, key2: key2}

I sometimes use this with lodash - use the following upon your first use of lodash to mix it in:

var _ = require('lodash');
_.mixin({keyMirror: require('keyMirror')});
// Can now be used as _.keyMirror(object)

Current Tags

  • 0.1.1                                ...           latest (6 years ago)

2 Versions

  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (1)
Today 196
This Week 904
This Month 420
Last Day 224
Last Week 1,031
Last Month 5,512
Dependencies (0)
Dev Dependencies (0)
Dependents (477)

Copyright 2014 - 2016 © |