fd22b0bf58
V2 (Laravel re-make)
40 lines
871 B
JavaScript
Vendored
40 lines
871 B
JavaScript
Vendored
'use strict';
|
|
|
|
/* eslint-disable eqeqeq */
|
|
|
|
var _require = require('../helpers/is'),
|
|
isArray = _require.isArray,
|
|
isObject = _require.isObject,
|
|
isFunction = _require.isFunction;
|
|
|
|
module.exports = function search(valueOrFunction, strict) {
|
|
var _this = this;
|
|
|
|
var result = void 0;
|
|
|
|
var find = function find(item, key) {
|
|
if (isFunction(valueOrFunction)) {
|
|
return valueOrFunction(_this.items[key], key);
|
|
}
|
|
|
|
if (strict) {
|
|
return _this.items[key] === valueOrFunction;
|
|
}
|
|
|
|
return _this.items[key] == valueOrFunction;
|
|
};
|
|
|
|
if (isArray(this.items)) {
|
|
result = this.items.findIndex(find);
|
|
} else if (isObject(this.items)) {
|
|
result = Object.keys(this.items).find(function (key) {
|
|
return find(_this.items[key], key);
|
|
});
|
|
}
|
|
|
|
if (result === undefined || result < 0) {
|
|
return false;
|
|
}
|
|
|
|
return result;
|
|
}; |