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.
31 lines
985 B
31 lines
985 B
var hasOwnProp = require('./hasOwnProp')
|
|
var isArray = require('./isArray')
|
|
|
|
function helperCreateIterateHandle (prop, useArray, restIndex, matchValue, defaultValue) {
|
|
return function (obj, iterate, context) {
|
|
if (obj && iterate) {
|
|
if (prop && obj[prop]) {
|
|
return obj[prop](iterate, context)
|
|
} else {
|
|
if (useArray && isArray(obj)) {
|
|
for (var index = 0, len = obj.length; index < len; index++) {
|
|
if (!!iterate.call(context, obj[index], index, obj) === matchValue) {
|
|
return [true, false, index, obj[index]][restIndex]
|
|
}
|
|
}
|
|
} else {
|
|
for (var key in obj) {
|
|
if (hasOwnProp(obj, key)) {
|
|
if (!!iterate.call(context, obj[key], key, obj) === matchValue) {
|
|
return [true, false, key, obj[key]][restIndex]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return defaultValue
|
|
}
|
|
}
|
|
|
|
module.exports = helperCreateIterateHandle
|
|
|