get-certain
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/get-certain package

1.0.1 • Public • Published

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 = 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.');

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

Readme

Keywords

none

Package Sidebar

Install

npm i get-certain

Weekly Downloads

8

Version

1.0.1

License

MIT

Unpacked Size

7.49 kB

Total Files

10

Last publish

Collaborators

  • wtg