object-only-value
Assert that object has only one key and return its value.
For when you want to do obj[Object.keys(obj)[0]]
, but know that if obj
somehow ended up with zero or more keys than one, it'd end in a disaster.
Literally:
var assert = ; module { var keys = Object; assert; return objkeys0;};
Installation
npm install object-only-value
Usage
var onlyValue = ;var obj = foo: 42 ;var theValue = ; // => 42 obj = {};theValue = ; // => throws obj = foo: 42 bar: 24 ;theValue = ; // => throws