sole-entry
Assert a Map has a given key and return the value for it.
Pretty much just map.get(key)
, but throws if key
isn't there.
Install
$ yarn add get-certain
Usage
const getCertain = ; const map = ; map; // Returns 1.; // This throws.; // This throws with a custom message.;
API
getCertain(map, key, [message])
Returns the value from map
for key
, or throws if it is not there.
map
- Type:
Map
A Map. I hope you know what you're putting in there.
key
- Type:
any
A key that is hopefully in map
.
message
- Type:
string
An optional message to throw. Defaults to '"map" does not have an entry for "key".', which isn't terribly descriptive.
License
MIT © Matthew Fernando Garcia