The JavaScript guru's KeyMirror-alternative. Functionally create constant hashes from any JavaScript object with greater performance.
Last updated a year ago by jameswomack .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install keykey 
SYNC missed versions from official npm registry.


Build Status via CodeShip Build Status

The shaman's KeyMirror-alternative.

  • Create enumerations
  • Functional-programming friendly (pass keys individually or as an array)
  • Performs well in hot code paths
  • Works in Node and browsers via Browerify
> require('keykey')( 'FOO', 'BAR', 'BAZ' )

	FOO: 'FOO',
	BAR: 'BAR',

KeyKey is a micro utility module which provides a consistent way to declare constants. KeyKey achieves a very simple task, but it tries to do so in a way that will encourage innovative use. KeyKey offers functional programming capabilities by allowing keys to be passed individually or via an array. KeyKey makes constants not just from strings, but also from any JavaScript object. It caches the resulting key mirrors, making subsequent calls faster. And this cache is accessible if needed, which could provide an interesting look into constants across your application. Check out the performance test in /test.

Plus, hey—no unnecessary nulls.


npm install keykey

Quick Start

Create constants with caching

const keykey = require('keykey')

// Arrays of keys
keykey(['foo','bar','baz']) // result -> {foo:'foo',bar:'bar',baz:'baz'}

// Individual keys
keykey('foo',true,'baz') // bools, if not in the final position, are treated as keys

Bypass the cache

keykey(['foo','bar','baz'], false) // no get/set
keykey('foo','bar','baz', false) // bools in the final position are treated as a cache switch

Clear the entire cache

keykey.reset() // or 

Current Tags

  • 3.0.0                                ...           latest (a year ago)

5 Versions

  • 3.0.0                                ...           a year ago
  • 3.0.0-alpha.0                                ...           a year ago
  • 2.1.1                                ...           5 years ago
  • 2.1.0                                ...           5 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Today 0
This Week 0
This Month 6
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (5)

Copyright 2014 - 2017 © |