fd22b0bf58
V2 (Laravel re-make)
24 lines
494 B
JavaScript
Vendored
24 lines
494 B
JavaScript
Vendored
'use strict';
|
|
|
|
var _require = require('../helpers/is'),
|
|
isFunction = _require.isFunction;
|
|
|
|
module.exports = function sole(key, operator, value) {
|
|
var collection = void 0;
|
|
|
|
if (isFunction(key)) {
|
|
collection = this.filter(key);
|
|
} else {
|
|
collection = this.where(key, operator, value);
|
|
}
|
|
|
|
if (collection.isEmpty()) {
|
|
throw new Error('Item not found.');
|
|
}
|
|
|
|
if (collection.count() > 1) {
|
|
throw new Error('Multiple items found.');
|
|
}
|
|
|
|
return collection.first();
|
|
}; |