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