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.
$ yarn add get-certain
const getCertain = require('get-certain');
const map = new Map();
map.set('foo', 1);
// Returns 1.
getCertain(map, 'foo');
// This throws.
getCertain(map, 'bar');
// This throws with a custom message.
getCertain(map, 'bar', 'This map is barless.');
Returns the value from map
for key
, or throws if it is not there.
- Type:
Map
A Map. I hope you know what you're putting in there.
- Type:
any
A key that is hopefully in map
.
- Type:
string
An optional message to throw. Defaults to '"map" does not have an entry for "key".', which isn't terribly descriptive.
MIT © Matthew Fernando Garcia