my-idlers/node_modules/collect.js/dist/methods/search.js
cp6 fd22b0bf58 V2 (Laravel re-make)
V2 (Laravel re-make)
2022-03-06 02:02:12 +11:00

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;
};