You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
871 B

4 years ago
'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;
};