ui
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
'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;
|
||||
};
|
||||
Reference in New Issue
Block a user