key-as
Create a new object from keys and fill value. #javascript
npm install key-as
API
keyAs(keys, value: undefined)
keys
is the array(-like) list of keys you want to usevalue
is an optional value for which to fill all keys with- Return is a new plain object with each key set to
value
Usage
import
or require
const keyAs =
Examples
Stub keys
// {red: undefined, blue: undefined} // {red: null, blue: null}
Scalar fill
// {red: 0, blue: 0} // {red: 1, blue: 1}
Reference fill
const noop = {}const hook = // {start: noop, stop: noop}hookstart === hookstop // true
Alias keys
const Batman = /* { "Batman": "Bruce Wayne", "The Dark Knight": "Bruce Wayne", "Caped Crusader": "Bruce Wayne",} */