Skip to content

Based on array input, create an object with values equal to its key names or symbol.

License

Notifications You must be signed in to change notification settings

builify/tt-keymirror

Repository files navigation

TTKeyMirror

Build Status Coveralls Status Code Climate NPM Version

Based on array input, create an object with values equal to its key names or symbol. Inspired by react/lib/keyMirror.

Installation

npm install ttkeymirror

Usage

import keyMirror from 'ttkeymirror';

const ACTIONS = keyMirror([
  'ACTION01',
  'ACTION02',
  'ACTION03'
]);

const action01 = ACTIONS.ACTION01;
const action02 = ACTIONS.ACTION02;
const action03 = ACTIONS.ACTION03;

If you want to use Symbol, simply add argument true after array.

const ACTIONS = keyMirror([
  'ACTION01',
  'ACTION02',
  'ACTION03'
], true);

/*
This will return following:
{
  ACTION01: Symbol('ACTION01'),
  ACTION02: Symbol('ACTION02'),
  ACTION03: Symbol('ACTION03')
}
*/

Contributions & Issues

Contributions are welcome. Please clearly explain the purpose of the PR and follow the current style.

Issues can be resolved quickest if they are descriptive and include both a reduced test case and a set of steps to reproduce.

Licence

Licensed under the MIT License © Trip-Trax 2015 - present.

About

Based on array input, create an object with values equal to its key names or symbol.

Resources

License

Stars

Watchers

Forks

Packages

No packages published