ssc-refer
Version:
React refer component for SSC 3.0
39 lines (28 loc) • 1.26 kB
JavaScript
;
exports.__esModule = true;
var _invariant = require('invariant');
var _invariant2 = _interopRequireDefault(_invariant);
var _lodash = require('lodash');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
/**
* Retrieves the display string from an option. Options can be the string
* themselves, or an object with a defined display string. Anything else throws
* an error.
*/
function getOptionLabel(option, labelKey) {
var optionLabel = void 0;
if (typeof option === 'string') {
optionLabel = option;
}
if ((0, _lodash.isPlainObject)(option)) {
if (typeof labelKey === 'string') {
optionLabel = option[labelKey];
} else if ((0, _lodash.isFunction)(labelKey)) {
optionLabel = labelKey(option);
}
}
!(typeof optionLabel === 'string') ? process.env.NODE_ENV !== 'production' ? (0, _invariant2['default'])(false, 'One or more options does not have a valid label string. Check the ' + '`labelKey` prop to ensure that it matches the correct option key and ' + 'provides a string for filtering and display.') : (0, _invariant2['default'])(false) : void 0;
return optionLabel;
}
exports['default'] = getOptionLabel;
module.exports = exports['default'];