Key Reflector
Generate objects with the same key and value.
Installation
npm install key-reflector --save
or
yarn add key-reflector
CDN:
<script src="https://unpkg.com/key-reflector/dist/umd/key-reflector.min.js"></script>
Usage
Basic
import KeyReflector from 'key-reflector'
KeyReflector.reflectKeys(['FOO', 'BAR', 'BAZ'])
returns:
{
FOO: 'FOO',
BAR: 'BAR',
BAZ: 'BAZ',
}
Syntax
KeyReflector.reflectKeys(keys[, options])
- keys
- Type:
[String]
- Keys to be reflected. Returns an object with the same key and value for each key.
- If
keys
is null, it will return an empty object{}
.
- Type:
- options (optional)
- Type:
Object
- The options for
reflectKeys
. See more in Options.
- Type:
Options
valuePrefix
- Type:
String
- Default:
''
Prefix to be added to each value.
Example:
KeyReflector.reflectKeys(['FOO', 'BAR', 'BAZ'], { valuePrefix: 'PREFIX_'})
returns:
{
FOO: 'PREFIX_FOO',
BAR: 'PREFIX_BAR',
BAZ: 'PREFIX_BAZ',
}